[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r19015: {torvm} Fix kernel cmdline parse error, pass hostname to vm now that (in torvm/trunk/build: kamikaze/patches win32/src/torvm-w32)
Author: coderman
Date: 2009-03-15 21:08:14 -0400 (Sun, 15 Mar 2009)
New Revision: 19015
Modified:
torvm/trunk/build/kamikaze/patches/001-kamikaze-tor-package.patch
torvm/trunk/build/kamikaze/patches/002-kamikaze-mod-basefiles.patch
torvm/trunk/build/win32/src/torvm-w32/torvm.c
Log:
Fix kernel cmdline parse error, pass hostname to vm now that it is expected, fix PATH default set in profile, run vidalia with info or debug logging enabled accordingly.
Modified: torvm/trunk/build/kamikaze/patches/001-kamikaze-tor-package.patch
===================================================================
--- torvm/trunk/build/kamikaze/patches/001-kamikaze-tor-package.patch 2009-03-15 11:02:48 UTC (rev 19014)
+++ torvm/trunk/build/kamikaze/patches/001-kamikaze-tor-package.patch 2009-03-16 01:08:14 UTC (rev 19015)
@@ -313,10 +313,11 @@
+
diff -Naur a/package/tor/files/tor.init b/package/tor/files/tor.init
--- a/package/tor/files/tor.init 1970-01-01 00:00:00.000000000 +0000
-+++ b/package/tor/files/tor.init 2009-03-15 04:23:29.661405512 +0000
-@@ -0,0 +1,116 @@
++++ b/package/tor/files/tor.init 2009-03-16 00:58:28.063736128 +0000
+@@ -0,0 +1,117 @@
+#!/bin/sh
-+
++# make sure we check the system bin dirs
++export PATH=/usr/sbin:/sbin:$PATH
+BIN=tor
+DEFAULT=/etc/default/$BIN
+HOME_D=/home/$BIN
@@ -373,7 +374,7 @@
+ fi;
+ chown $RUN_USER:$RUN_GROUP $CONF_F
+ # start tor process
-+ $BIN -f $CONF_F $OPTIONS > $SLOG_F 2>&1
++ $BIN -f $CONF_F > $SLOG_F 2>&1
+ # TODO for now used fixed control port and socks port accept rule
+ iptables -t nat -I PREROUTING -i $TOR_INTF -d $MYIP -p tcp --dport 9051 -j ACCEPT
+ iptables -t nat -I PREROUTING -i $TOR_INTF -d $MYIP -p tcp --dport 9050 -j ACCEPT
Modified: torvm/trunk/build/kamikaze/patches/002-kamikaze-mod-basefiles.patch
===================================================================
--- torvm/trunk/build/kamikaze/patches/002-kamikaze-mod-basefiles.patch 2009-03-15 11:02:48 UTC (rev 19014)
+++ torvm/trunk/build/kamikaze/patches/002-kamikaze-mod-basefiles.patch 2009-03-16 01:08:14 UTC (rev 19015)
@@ -1229,7 +1229,7 @@
-tty1::askfirst:/bin/ash --login
diff -Naur a/package/base-files/files/etc/preinit b/package/base-files/files/etc/preinit
--- a/package/base-files/files/etc/preinit 2008-08-14 22:21:35.073308000 +0000
-+++ b/package/base-files/files/etc/preinit 2009-03-15 04:14:48.433644176 +0000
++++ b/package/base-files/files/etc/preinit 2009-03-16 00:58:48.775587448 +0000
@@ -1,88 +1,231 @@
#!/bin/sh
-# Copyright (C) 2006 OpenWrt.org
@@ -1286,7 +1286,7 @@
+HOSTNAME="Tor_VM"
+echo $ARGS | grep ' USEHOSTNAME=' >/dev/null 2>&1
+if [ $? -eq 0 ]; then
-+ HOSTNAME=`echo $ARGS | sed 's/.* USEHOSTNAME=//' | sed 's/ .*//' | sed 's/[^0-9a-zA-Z-_]//g'`
++ HOSTNAME=`echo $ARGS | sed 's/.* USEHOSTNAME=//' | sed 's/ .*//' | sed 's/[^0-9a-zA-Z_-]//g'`
+fi
+export HOSTNAME
+hostname "$HOSTNAME" >/dev/null 2>&1
@@ -1430,8 +1430,8 @@
+ export IP=`echo $ARGS | sed 's/.* IP=//' | sed 's/ .*//' | sed 's/[^0-9.]//g'`
+ export MASK=`echo $ARGS | sed 's/.* MASK=//' | sed 's/ .*//' | sed 's/[^0-9.]//g'`
+ export GW=`echo $ARGS | sed 's/.* GW=//' | sed 's/ .*//' | sed 's/[^0-9.]//g'`
-+ export MAC=`echo $ARGS | sed 's/.* MAC=//' | sed 's/ .*//' | sed 's/[^0-9.]//g'`
-+ MTU=`echo $ARGS | sed 's/.* MTU=//' | sed 's/ .*//' | sed 's/[^0-9.]//g'`
++ export MAC=`echo $ARGS | sed 's/.* MAC=//' | sed 's/ .*//' | sed 's/[^0-9a-fA-F:.]//g'`
++ MTU=`echo $ARGS | sed 's/.* MTU=//' | sed 's/ .*//' | sed 's/[^0-9]//g'`
+ export ISDHCP=0
+ dn "Setting IP $IP / $MASK via $GW ..."
+ ifconfig eth0 hw ether $MAC
@@ -1441,7 +1441,7 @@
+ echo $ARGS | grep ' ISDHCP ' >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ export ISDHCP=1
-+ export DHCPSVR=`echo $ARGS | sed 's/.* DHCPSVR=//' | sed 's/ .*//'`
++ export DHCPSVR=`echo $ARGS | sed 's/.* DHCPSVR=//' | sed 's/ .*//' | sed 's/[^0-9.]//g'`
+ export DHCPNAME=`echo $ARGS | sed 's/.* DHCPNAME=//' | sed 's/ .*//'`
+ # fire up udhcpc to keep the lease active for however long is needed
+ udhcpc -b -h $DHCPNAME -r $IP -i eth0 -p /var/run/dhcp.eth0.pid >/dev/null 2>&1 &
@@ -1527,13 +1527,9 @@
fi
diff -Naur a/package/base-files/files/etc/profile b/package/base-files/files/etc/profile
--- a/package/base-files/files/etc/profile 2009-01-07 04:38:57.851159000 +0000
-+++ b/package/base-files/files/etc/profile 2009-03-15 04:12:57.481511464 +0000
-@@ -1,15 +1,11 @@
- #!/bin/sh
- [ -f /etc/banner ] && cat /etc/banner
-
--export PATH=/bin:/sbin:/usr/bin:/usr/sbin
-+export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/etc/init.d
++++ b/package/base-files/files/etc/profile 2009-03-16 00:59:14.150729840 +0000
+@@ -4,12 +4,8 @@
+ export PATH=/bin:/sbin:/usr/bin:/usr/sbin
export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6)
export HOME=${HOME:-/root}
-export PS1='\u@\h:\w\$ '
Modified: torvm/trunk/build/win32/src/torvm-w32/torvm.c
===================================================================
--- torvm/trunk/build/win32/src/torvm-w32/torvm.c 2009-03-15 11:02:48 UTC (rev 19014)
+++ torvm/trunk/build/win32/src/torvm-w32/torvm.c 2009-03-16 01:08:14 UTC (rev 19015)
@@ -23,6 +23,7 @@
#define TOR_HDD_FILE "hdd.img"
#define QEMU_DEF_MEM 32
#define CAP_MTU 1480
+#define CMDMAX 4096
BOOL buildpath (const TCHAR *dirname,
TCHAR **fullpath);
@@ -98,7 +99,7 @@
const char * format,
va_list argptr)
{
- static const int msgmax = 4096;
+ static const int msgmax = CMDMAX;
static char * msgbuf = NULL;
static char * coff = NULL;
const char * newline = "\r\n";
@@ -239,13 +240,12 @@
LPTSTR append,
LPTSTR *fpath)
{
-#define BUFSZ 4096
DWORD retval;
DWORD errnum;
LPTSTR defval = NULL;
LPTSTR envvar;
LPTSTR dsep = "\\";
- *fpath = malloc(BUFSZ * sizeof(TCHAR));
+ *fpath = malloc(CMDMAX * sizeof(TCHAR));
if(*fpath == NULL) {
lerror ("buildsyspath: out of memory.");
free(envvar);
@@ -265,7 +265,7 @@
envvar = getenv("USERPROFILE");
if(!envvar) {
if (defval) {
- strncpy(*fpath, defval, (BUFSZ -1));
+ strncpy(*fpath, defval, (CMDMAX -1));
return TRUE;
}
free(*fpath);
@@ -277,7 +277,7 @@
if (syspathtype == SYSDIR_LCLPROGRAMS)
lclpost = "Programs";
/* local appdata and programs is built against the user profile root */
- snprintf (*fpath, (BUFSZ -1),
+ snprintf (*fpath, (CMDMAX -1),
"%s%s%s%s%s%s%s",
envvar,
dsep,
@@ -288,7 +288,7 @@
append ? append : "");
}
else {
- snprintf (*fpath, (BUFSZ -1),
+ snprintf (*fpath, (CMDMAX -1),
"%s%s%s",
envvar,
append ? dsep : "",
@@ -296,7 +296,6 @@
}
return TRUE;
}
-#undef BUFSZ
/* initial attempt to keep file locations dynamic and configurable.
*/
@@ -404,7 +403,7 @@
LPTSTR destpath)
{
HANDLE src, dest;
- DWORD buffsz = 4096;
+ DWORD buffsz = CMDMAX;
DWORD len, written;
LPTSTR buff;
src = CreateFile (srcpath,
@@ -718,7 +717,7 @@
LPTSTR srcname = NULL;
LPTSTR destname = NULL;
CHAR * buff = NULL;
- DWORD buffsz = 4096;
+ DWORD buffsz = CMDMAX;
DWORD len;
DWORD written;
if (!buildsyspath(SYSDIR_WINROOT, WIN_DRV_DIR "\\" TOR_CAP_SYS, &destname)) {
@@ -1549,10 +1548,16 @@
char ** cmdline)
{
/* DHCPSVR DHCPNAME LEASE ISDHCP CTLSOCK HASHPW */
- const DWORD cmdlen = 4096;
+ const DWORD cmdlen = CMDMAX;
*cmdline = malloc(cmdlen);
const char * basecmds = "quiet loglevel=0 clocksource=hpet";
const char * dbgcmds = "loglevel=9 clocksource=hpet DEBUGINIT";
+
+ /* Give the VM our hostname, since it is assuming the host's place in the network. */
+ char * myhostname = getenv("COMPUTERNAME");
+ if (!myhostname)
+ myhostname = getenv("HOSTNAME");
+
/* control port password is "password"
* TODO: use Crypto API to collect entropy for ephemeral password generation
*/
@@ -1566,8 +1571,10 @@
else {
if (brif->isdhcp == FALSE) {
snprintf (*cmdline, cmdlen -1,
- "%s IP=%s MASK=%s GW=%s MAC=%s MTU=%d PRIVIP=%s CTLSOCK=%s:9051 HASHPW=%s",
+ "%s%s%s IP=%s MASK=%s GW=%s MAC=%s MTU=%d PRIVIP=%s CTLSOCK=%s:9051 HASHPW=%s",
usedebug ? dbgcmds : basecmds,
+ myhostname ? " USEHOSTNAME=" : "",
+ myhostname ? myhostname : "",
brif->ipaddr,
brif->netmask,
brif->gateway,
@@ -1578,9 +1585,15 @@
ctlpass);
}
else {
+ /* fallback if we can't get HOSTNAME, use DHCP client name. */
+ if (!myhostname)
+ myhostname = brif->dhcpname;
+
snprintf (*cmdline, cmdlen -1,
- "%s IP=%s MASK=%s GW=%s MAC=%s MTU=%d PRIVIP=%s ISDHCP DHCPSVR=%s DHCPNAME=%s CTLSOCK=%s:9051 HASHPW=%s",
+ "%s%s%s IP=%s MASK=%s GW=%s MAC=%s MTU=%d PRIVIP=%s ISDHCP DHCPSVR=%s DHCPNAME=%s CTLSOCK=%s:9051 HASHPW=%s",
usedebug ? dbgcmds : basecmds,
+ myhostname ? " USEHOSTNAME=" : "",
+ myhostname ? myhostname : "",
brif->ipaddr,
brif->netmask,
brif->gateway,
@@ -1617,9 +1630,9 @@
return FALSE;
}
- TCHAR *cmd = malloc(4096);
+ TCHAR *cmd = malloc(CMDMAX);
/* TODO: clean this up once the msys path munging works. kernel and hdd need to be unixy paths */
- snprintf (cmd, 4095,
+ snprintf (cmd, CMDMAX -1,
"\"%s\" -L . -kernel ../lib/vmlinuz -hda ../state/hdd.img -m %d -std-vga", qemubin, QEMU_DEF_MEM);
ldebug ("Launching Qemu with cmd: %s", cmd);
if( !CreateProcess(NULL,
@@ -1638,12 +1651,14 @@
return TRUE;
}
-BOOL runvidalia ()
+BOOL runvidalia (BOOL indebug)
{
+ BOOL retval = FALSE;
PROCESS_INFORMATION pi;
STARTUPINFO si;
SECURITY_ATTRIBUTES sattr;
- LPTSTR cmd = NULL;
+ TCHAR * cmd = NULL;
+ LPTSTR exe = NULL;
LPTSTR dir = NULL;
LPTSTR vcfgtmp = NULL;
LPTSTR pcfgtmp = NULL;
@@ -1657,34 +1672,34 @@
if (!buildfpath(PATH_FQ, VMDIR_LIB, NULL, "defvidalia.conf", &vcfgtmp)) {
lerror ("Unable to build path for default vidalia config file.");
- return FALSE;
+ goto cleanup;
}
if (!buildfpath(PATH_FQ, VMDIR_LIB, NULL, "defpolipo.conf", &pcfgtmp)) {
lerror ("Unable to build path for default polipo config file.");
- return FALSE;
+ goto cleanup;
}
if (!buildsyspath(SYSDIR_LCLDATA, "Vidalia", &dir)) {
lerror ("Unable to build path for Vidalia programs dir.");
- return FALSE;
+ goto cleanup;
}
if (!buildsyspath(SYSDIR_LCLDATA, "Vidalia\\vidalia.conf", &vcfgdest)) {
lerror ("Unable to build path for vidalia dest config file.");
- return FALSE;
+ goto cleanup;
}
if (!buildsyspath(SYSDIR_LCLDATA, "Vidalia\\polipocfg.txt", &pcfgdest)) {
lerror ("Unable to build path for polipo dest config.");
- return FALSE;
+ goto cleanup;
}
- if (!buildsyspath(SYSDIR_LCLPROGRAMS, "Vidalia\\vidalia-marble.exe", &cmd)) {
+ if (!buildsyspath(SYSDIR_LCLPROGRAMS, "Vidalia\\vidalia-marble.exe", &exe)) {
lerror ("Unable to build path for vidalia marble exe.");
- return FALSE;
+ goto cleanup;
}
- if (!exists(cmd)) {
+ if (!exists(exe)) {
/* assume not a marble vidalia install */
- free (cmd);
- if (!buildsyspath(SYSDIR_LCLPROGRAMS, "Vidalia\\vidalia.exe", &cmd)) {
+ free (exe);
+ if (!buildsyspath(SYSDIR_LCLPROGRAMS, "Vidalia\\vidalia.exe", &exe)) {
lerror ("Unable to build path for vidalia exe.");
- return FALSE;
+ goto cleanup;
}
}
if (!exists(vcfgdest)) {
@@ -1696,6 +1711,12 @@
copyfile(pcfgtmp, pcfgdest);
}
+ cmd = malloc(CMDMAX);
+ snprintf (cmd, CMDMAX -1,
+ "\"%s\"%s",
+ exe,
+ indebug ? " -loglevel debug -logfile debuglog.txt" :
+ " -loglevel info -logfile infolog.txt");
ldebug ("Launching Vidalia in dir: %s , with cmd: %s", dir, cmd);
if( !CreateProcess(NULL,
cmd,
@@ -1708,9 +1729,29 @@
&si,
&pi) ) {
lerror ("Failed to launch process. Error code: %d", GetLastError());
- return FALSE;
+ goto cleanup;
}
- return TRUE;
+ else {
+ retval = TRUE;
+ }
+
+ cleanup:
+ if(cmd)
+ free(cmd);
+ if(exe)
+ free(exe);
+ if(dir)
+ free(dir);
+ if(vcfgtmp)
+ free(vcfgtmp);
+ if(pcfgtmp)
+ free(pcfgtmp);
+ if(vcfgdest)
+ free(vcfgdest);
+ if(pcfgdest)
+ free(pcfgdest);
+
+ return retval;
}
BOOL launchtorvm (PROCESS_INFORMATION * pi,
@@ -1726,8 +1767,8 @@
SECURITY_ATTRIBUTES sattr;
LPTSTR cmd = NULL;
LPTSTR dir = NULL;
- /* DWORD opts = BELOW_NORMAL_PRIORITY_CLASS; */
- DWORD opts = CREATE_NEW_PROCESS_GROUP;
+ /* If Tor VM Qemu instance is not below normal prio, performance of host suffers. */
+ DWORD opts = CREATE_NEW_PROCESS_GROUP | BELOW_NORMAL_PRIORITY_CLASS;
DWORD numwritten;
DWORD pipesz;
LPTSTR qemubin = NULL;
@@ -1748,9 +1789,9 @@
/* sattr.nLength = sizeof(SECURITY_ATTRIBUTES);
sattr.bInheritHandle = TRUE;
sattr.lpSecurityDescriptor = NULL; */
- cmd = malloc(4096);
+ cmd = malloc(CMDMAX);
if (tapname) {
- snprintf (cmd, 4095,
+ snprintf (cmd, CMDMAX -1,
"\"%s\" -name \"Tor VM \" -L . -kernel ../lib/vmlinuz -append \"%s\" -hda ../state/hdd.img -m %d -std-vga -net nic,model=pcnet,macaddr=%s -net pcap,devicename=\"%s\" -net nic,vlan=1,model=pcnet -net tap,vlan=1,ifname=\"%s\"",
qemubin,
cmdline,
@@ -1760,7 +1801,7 @@
tapname);
}
else {
- snprintf (cmd, 4095,
+ snprintf (cmd, CMDMAX -1,
"\"%s\" -name \"Tor VM \" -L . -kernel ../lib/vmlinuz -append \"%s\" -hda ../state/hdd.img -m %d -std-vga -net nic,model=pcnet,macaddr=%s -net pcap,devicename=\"%s\"",
qemubin,
cmdline,
@@ -1902,8 +1943,8 @@
LPTSTR args = "";
bgstartupinfo (&si);
getmypath(&mypath);
- cmd = malloc (4096);
- snprintf (cmd, 4095,
+ cmd = malloc (CMDMAX);
+ snprintf (cmd, CMDMAX -1,
"\"%s\" %s",
mypath, args);
if( !CreateProcess(NULL,
@@ -2294,7 +2335,7 @@
* for the 10. tap control port and externally managed Tor instance.
*/
if (bundle) {
- runvidalia();
+ runvidalia(indebug);
}
/* TODO: once the pcap bridge is up we can re-enable the firewall IF we