Virtual PC connection to the host while on the road

This advice is for Microsoft Virtual PC. When you use software like VMWare, it automatically allows the host to connect directly to the client using the virtual interfaces that have been created.

Most of the recommendations with regard to connection to/from the Virtual PC client recommend configuring the connection to share/bridge one of the network connections.

All very good and well when you’re on a network. I regularly use the system when I have no network available – i.e. I’m completely disconnected. Most of the connection sensing code for network adaptors prevent you from using it while it’s not active, plus I don’t like having to configure the connection manually and then reconfigure it when I’ve got a real network.

The simple solution is to add a Microsoft Loopback Adaptor to the host machine, then create a second network interface on the Virtual PC that uses this interface. Manually configure the IP addresses to be on the same private network, making sure that you don’t accidentally configure it to use an IP address range that you may end up using for a VPN connection.

  1. Add the Network Adaptor: XP, Vista, Windows 7
  2. Configure the IP address manually. Use a Private Address Range. I chose an IP address of 10.125.1.1 with a netmask of 255.255.255.0 for the host, then chose 10.125.1.2 for the Virtual machine. XP, Vista, Windows 7 – Use the instructions for Vista.
  3. Shutdown the Virtual Machine, Don’t hibernate as you can’t add the second network interface.
  4. Edit the properties of the virtual machine (in the Virtual Machines folder). Either Right Click on the Virtual Machine Icon, or use the Settings Option in the menu bar.
    Settings Option
  5. Configure the network to have 2 interfaces, one of which is linked to the ‘Microsoft Loopback Adaptor’
    Settings Dialog
  6. Boot up the virtual machine, and follow the instructions for manually configuring the IP address of this new network interface.

Direct connections to the IP address of the client virtual machine now work, and you can use it for anything you want.

Following the instructions here, even if they’re confusing, once you add a dword key called ‘*NdisDeviceType’, with a value of 1, you don’t see the connection as an unknown connection; thus enabling sharing and other features in Vista, Win 7.

Password recovery from open applications

Well I had a minor hiccup today when I decided it was ‘password change day’. I duly went around changing the password on all my systems. Then I got back to work. 10 minutes later I turned to my other system and typed in the password.
… It didn’t work …
I smacked my head and said to myself “D’oh”, I need to use the new password. But I couldn’t remember all of it. All I had was a few characters I could remember and the fact that my mail program was checking the mail every few minutes and still working.

First I got the pid of thunderbird…

~% ps -fe | grep thunder
1000     17509     1  0 13:19 ?        00:00:00 /bin/sh /usr/bin/thunderbird
1000     17521 17509  0 13:19 ?        00:00:00 /bin/sh /usr/lib/thunderbird/run-mozilla.sh /usr/lib/thunderbird/thunderbird-bin
1000     17526 17521  0 13:19 ?        00:00:24 /usr/lib/thunderbird/thunderbird-bin
1000     19101 19006  0 14:09 pts/10   00:00:00 grep thunder

Then I got the address of the heap from the process’ maps

~% grep 'heap' /proc/17526/maps
08d02000-0a9ad000 rw-p 08d02000 00:00 0          [heap]

I compiled up memory_dumper, and ran it against the process and heap addresses listed.

% ./memory_dumper 08d02000 0a46a000 17526 heap

Then I ran strings on the resulting file, looking for the pattern that matched my remembered password

% strings heap | grep t%7
cheat%7Ladel
cheat%7Ladel
cheat%7Ladel
cheat%7Ladel
%

4 copies of the password in memory in the program. That is just in-freaking-sane. It should be present in the program only once, and should probably be concealed using some form of obfuscation. Mind you, it has kept the new password in my mind now, so I should be grateful.

And just in case you feel like trying the password listed, don’t. It’s not the real password 😉

automatically sending text messages from email messages

Using the natty little webtext script (updated to use an $HOME/.webtextrc file for the username/password) and a little bit of procmail magic, we can now send messages containing the subject line of a specific email message once it has been received.
Firstly, there’s the .procmailrc file. The recipe I’m using looks like:

# send text messages
:0 W
* ^subject: IM:
| $HOME/bin/sendim

The script sendim is a simple bash script that checks the subject line contains “IM: ” and then sends on the remainder of the subject line as a text message to my mobile phone.
As a security precaution, I’ve added a special header ‘X-apikey’ which is checked by the sendim. If the apikey doesn’t match then the rule doesn’t fire. You should replace the XXX item with your own value generated using echo <some text here> | sha1sum. By not putting the api check in the .procmailrc file you can quietly drop messages that don’t have the correct key instead of keeping them in your inbox.

#!/bin/bash -p

export PATH=$HOME/bin:$PATH

subject=
apikey=
apikey_c="XXX"

while read foo; do
    [[ -z $foo ]] && break
    subject=${subject:-$(echo $foo | sed -n "s/[sS]ubject: IM: //p")}
    apikey=${apikey:-$(echo $foo | sed -n "s/X-apikey: //p")}
done

if [[ -n $subject && $apikey = $apikey_c ]]; then
    webtext -t YYY "$subject" >/dev/null 2>&1
fi

Source of sendim. Don’t forget to replace the XXX and YYY with your chosen items.

Don’t hide or disable menu items…

Firefox 'dialog' The suggestion by Joel to not hide or disable menu items is a good one. There’s only one issue. With the way it’s worded you could end up with a swarm of dialogs. I would suggest some form of stackable notification item. The status bar isn’t really suitable for this as there’s no way to get stuff back from it historically.
The ‘in frame‘ dialog that’s becoming popular these days in such browsers as Firefox. This is a reasonable ‘dialog’, and you could remove them automatically after a period of time (say 30 seconds). as long as they are differentiated from the other items on the screen it would be reasonable.

For a text mode browser links is pretty useful

How can you tell if your website is usable by anyone? Well one of the simplest ways is to use a text mode browser. It gives you a good idea as to how easy it is to navigate without having to spend the effort getting in a UI designer at infinity$/hour just to tell you that your links should be purple, and not help you in the least bit.
links is a pretty damned good text mode browser. It makes it obvious if you’ve made a mess of the UI for navigating, which is always a good thing. It makes it obvious when you’ve forgotten to put the bloody ALT tags into all your images – like a good designer should. Spacer gifs are evil and must be stopped 🙂

Wonderfully documented evolution email client

Evolution doesn’t really tell you that when you use a script to generate your signature you need to terminate the lines with a ‘<br/>’, otherwise it pretends that there hasn’t been one.
All to do with html mail composition. The only way I accidentally found this out was because of it’s gconf entry containing this gem:

<?xml version="1.0"?>
<signature name="default" uid="XXX@XXX" auto="false" format="text/html">
<filename script="true">sig.work</filename>
</signature>

Using snapshots would make ‘don’t install into /usr/local’ easier

Strangely enough, I had actually thought of this before I made the post. Snapshots are a wonderful feature in zfs which allow you to take point in time images of a filesystem that are mutable and which themselves can be snapshotted.
Unfortunately, this leads an explosion of snapshots if we want to be able to arbitrarily remove any one application from the system.
Consider the following operation:

pkg(1) + pkg(2) + pkg(3)

Now remove pkg(2) without using anything other than snapshots.
snapshot before adding anything sn(0). snapshot after adding package 1 sn(1)(sn(0)). snapshot after adding package2 sn(2)(sn(0)) + sn(2)(sn(1)). snapshot after adding package3 sn(3)(sn(0)) + sn(3)(sn(2)) + sn(3)(sn(1)).
Repeat for arbitrary pkg(n).

Unless you’re planning on creating a whole travelling salesmanOk, it’s not quite the travelling salesman problem, but it gives you a good idea as to how much work is involved of snapshots, I think my mechanism is easier.

Don’t just install everything into /usr/local

If you use windows then this is probably going to be very, very boring.
Every now and again you find yourself needing to install some piece of software on your computer from a source package. You tar xjf the package and descend into the subdirectory and type ./configure.
At this point I would yell stop! Rather than putting it into the default location of /usr/local, consider putting it in /usr/local/<package-version>.
How does this help I hear you ask. Well, using a simple script (in the extended entry), you create a set of symbolic links in the /usr/local directories which reference the files in the /usr/local/<package-version> directories.
If you decide to remove the package then simply remove the /usr/local/<package-version> directory and all the symlinks become broken. By using symlinks -rd /usr/local you clean the file system up and everything is peachy. If you don’t have a copy of symlinks, it is available from the debian repository, where you should find the source package somewhere near the bottom.

#!/bin/bash -p
package=$1
destdir=${2:-/usr/local}
me=${0##*/}
[[ -z $package ]] && {
echo "Usage: $me <package> [destination = /usr/local]"
exit 2
}
cd $destdir/$package || {
echo "$me: package $package does not seem to be installed"
exit 1
}
# build the directory structure - this is a weakness
find . -type d | cpio -o | (cd $destdir; cpio -id)
find . -type f -exec $echo ln -s $destdir/$package/{} ../{} \;

Oh, and for solaris, as I’m using the file in various locations surrounded by symbols you will have to just pass it into a sub-program to execute the link command. Apparently solaris doesn’t just substitute the name of the target for the link; instead it will only substitute the name of the target when it is isolated (i.e. you would need to use the {} on their own without anything surrounding them – which explains the space between the closing brace and the backslashed semicolon – old habits). I supposed I could throw a bit of perl at this problem but… it works on my box so frell the rest of you :).
Meh, the entire problem is annoying; generally I would always have to create a program to process the {} operation anyway to prevent space characters from getting in the way but as we say in the trade 99% is better than 0%. If you want a 100% solution you need to add a script that performs the link – one per line produced from the find.

Differences between the busybox shell and the real bourne shell

Feature Bourne Shell Busybox Shell Bash
Subprocess Execution “ (the backtick) “ or $() As Busybox
Math Evaluation use expr (not builtin) $(( )) As Busybox; adds ((var=math))
Constants None None typeset -r
Integers None None typeset -i
Evaluation [ [ [
Extended Evaluation /bin/[[ (1) /bin/[[ (1) [[


(1)
The [[ operator is not the same as the program /bin/[[ as a program you need to still use double quotes around the variables to be expanded; thus defeating the reason for having them in the first place.

For Example:

# file="/tmp/let me go"
# touch "$file"
# [[ -e $file ]] && echo "There"

Yields [Busybox]:

[[: me: unknown operand

– as $file is word split before handing it to the command [[

Yields :

There

– due to $file not being split when passed to the test -e.