Day 01- A recent picture of you and 15 interesting facts about yourself

To start of the 30 days of me blogging challenge here is the day 01 post containing 15 (hopefully) interesting facts about me as well as a recent picture (or three since I’m bit of a camwhore).

1. I’m somewhat of a workaholic. Actually, that would be an understatement, I’m regularly doing 60 to 80 hour weeks and spending far too much time on a computer.

2. My family unit consists of myself, mum, dad and a younger brother. Dad is from the UK, don’t have much to do with that side of the family, and mum is from NZ. Tend to see mum’s parents semi-frequently, but outside of that I don’t associate with my extended family.

Like my dad always says, “Family stops at front door”. ;-) I just tend not to see a need to associate with them when I share no interests, just because they’re family.

3. I run a Wellington-based IT startup company called Amberdms, focusing on open source software and solutions. This means I get no sleep, work insane hours and am constantly hurrying around doing ten things at once.

4. I’m single. I’ve dated a bit and had a few flings, but never really formed a proper relationship with anyone. I recently started dating again to (somewhat) disastrous and/or amusing results depending on your point of view ;-)

5. According to my twitter followers, I’m known to be obsessed with cougars. In reality, I tend to subconsciously fancy older women, simply on the basis that we tend to interact and relate better.

My dating age range tends to be 18-30, lately I’ve been exploring the upper levels of that range and met some awesome ladies, although I think the age gap is a problem for some – I fear I may be cursed to be single until I’m in my 30s :-/

6. I’m younger than I look or behave – many people believe that I am around 25 but that’s a little off…

7. There are frequent debates about my sanity. In my defence, I’ve never been *proven* to be insane. I’d also like to point out that genius often borders on madness ;-) I might also mention I have a slight ego here…

8. I got into computers properly around intermediate school and was hooked on Linux within my first year of college (high-school for you American/international readers), starting off with Mandrake 6 and later moving to Red Hat 8 and onwards.

For a couple years I had my own Linux distribution (Jedo Linux) as a fun side project, which also taught me far too much about packaging, compiling and how a Linux operating system fits together.

9. I’m a born and bred Wellingtonian, although have been to a number of places in NZ and AU, mostly for business or conferences. Don’t have any particular plans to travel in the near future, I like it here and business somewhat ties me to Wellington.

10.  I’m a bitter, godless, atheist, I have very little time for religion – which will get me in trouble sometimes since I tend to open my mouth too much.

I think part of the problem is I can’t see any way someone could believe in religion and it really surprises me when I discover that someone I know has beliefs.

Having said that, I don’t really mind people who are religious for the right reasons (eg: caring about others, being good to people and having their own beliefs) rather than some religious believers who use it to try and silence or suppress things they dislike or try enforcing their beliefs via legislation or constant campaigning.

I’ve met some pretty amazing and caring people and cute couples who find that religion helps them, but I’m not sure it’s something I can ever understand.

11. Of course being a bitter godless atheist doesn’t mean I don’t have morals/ethics/beliefs – I’ve been lacto-octo vegetarian since 2008 and slowly moving towards veganism. This was slowly brought on by considering the fact that I’d never hurt a pet, yet was eating animals of equilivent intelligence, so I made the jump in 2008 and haven’t looked back.

I’m a pretty lazy cook, so I’m not exactly the most healthy vegetarian as you’ll quickly realise reading some of my posts/tweets. ;-)

I try to avoid being the whole “fanatical vegetarian” but I do have some pretty strong opinions about it and sometimes get into “vigorous debates” over the issue.

12. I flat with my friend Tom. Being a meat eater and opinionated, we tend to have interesting debates and philosophical discussions about just about everything anywhere.

13. I’m a strong believer in open source, my laptop runs Fedora Linux and running an almost entirely open source stack (there are a couple proprietary applications for work). Linux and open source has been a huge part of my life, both in getting me a job, but also as a way of making heaps of smart, fantastic friends and developing strong morals/beliefs about freedom, information, government and more. It’s probably one of the largest influences in my life.

14. At times I suffer from being somewhat egotistical and overly demanding with requests – something I’m trying to avoid.

15. I’m an infoholic – addicted to email, twitter and RSS feeds. I read almost every single message I ever get, which can take a bit too much time sometimes.

30 posts in 30 days challange

So one of the major motivations for upgrading my blog to WordPress is that I wanted to take part in the 30 posts in 30 days challange and get back into blogging, like I was in 2007/2008.

I’m not sure where this whole “30 days of me” originally came from, I’m going to blame @pebblesy entirely since I think she was the first person tweeting about it that made me take notice.

Since the start of the day, it’s taken off in storm and whole pile of my twitter and real-life friends have joined up for it and created blogs.

I figured I’d better join in all the fun (and I’m always up for getting involved in anything with large numbers of lovely ladies) so managed to find a couple hours and ported across most of the key data off my old blog to this one.

To give you an idea of the size of this, pebblesy created a page with other twitter users who are also taking part, the list is quite extensive: http://pebblesy.wordpress.com/2010/09/07/30-days-of-me-meet-my-fellow-challengies/

The whole concept of the 30 days is to answer a different question or topic every day, the list that I’ve been floating around is:

Day 01- A recent picture of you and 15 interesting facts about yourself
Day 02- The meaning behind your Blog name
Day 03- A picture of you and your friends
Day 04- A habit that you wish you didn’t have
Day 05- A picture of somewhere you’ve been to
Day 06- Favourite super hero and why
Day 07- A picture of someone/something that has the biggest impact on you
Day 08- Short term goals for this month and why
Day 09- Something you’re proud of in the past few days
Day 10- Songs you listen to when you are Happy, Sad, Bored, Hyped, Mad
Day 11- Another picture of you and your friends
Day 12- How you found out about blogging and why you made one
Day 13- A letter to someone who has hurt you recently
Day 14- A picture of you and your family
Day 15- What are your favourite songs [adjusted from ipod list]
Day 16- Another picture of yourself
Day 17- Someone you would want to switch lives with for one day and why
Day 18- Plans/dreams/goals you have
Day 19- Nicknames you have; why do you have them
Day 20- Someone you see yourself marrying/being with in the future
Day 21- A picture of something that makes you happy
Day 22- What makes you different from everyone else
Day 23- Something you crave for a lot
Day 24- A letter to your parents
Day 25- What I would find in your bag
Day 26- What you think about your friends
Day 27- Why are you doing this 30 day challenge
Day 28- A picture of you last year and now, how have you changed since then?
Day 29- Your favourite song.
Day 30- In this past month, what have you learned

It’s a somewhat different slant from my usual geekary, but if you only want purely geekary, you are always able to select the categories to limit what you get from this blog to just that. :-)

Anyway, it should be fun – I’ll be starting day one tomorrow. If you’re on twitter, following along the fun with the hash tag #30daysofme or you can follow a super RSS compilation feed that pebblesy made.

First post! (From android)

Trying out the wordpress application from Android, looks pretty nifty.

You can add pictures straight from the phone as well which is habdy, ill try to do a bit more blogging and less tweeting with this. :-)

Upgraded to WordPress

For a long time I’ve been asked “when are you getting an RSS feed” and “when is your blog getting updated?”.

I’ve been pretty busy and haven’t had the time to upgrade my custom built system dating back to 2006, so I’ve finally decided to make the jump to WordPress, since it’ll make the maintenance and upgrading of it so much easier in future.

I’m also aiming to start blogging a bit more frequently, beginning with the 30-days blogging challenge that started up on Twitter – more about this soon – as well as being able to blog from my smart phone whilst on the go. :-)

At this stage, some of the old content is still missing, as I am slowly importing and reformatting/fixing a lot of materials – if you want to access the old site for anything, you can still reach it at: https://www.jethrocarr.com/old/

Linux on Lenovo X201i Laptop

Sadly after almost 5 years of loyal service, my beloved Libretto U100 recently started showing signs of it’s age by crashing randomly and struggling to keep up with my daily tasks.

To replace it, I wanted something both lightweight and portable, but also powerful to keep up with all the large documents and projects I’m working on.

I ended up selecting a Lenovo X201i laptop, Lenovo’s ultraportable model.

THE LAPTOP

With a 12″ widescreen LCD and weight of about 1.5kg, it’s certainly larger than my Libretto, but a great compromise between usability and portability. Having a fullsize keyboard is another major advantage and it certainly makes the laptop more productive on the go.

I also purchase the extended 9-cell battery, which gets me about 7 hours life, enough to get me through a day of customer meetings.

Over all it’s a fantastic machine, and with a Intel Core i5 and 4GB of RAM packed into the system it’s a fast system able to tackle everything I throw at it.

It’s an opinion damnit!

Being a highly opinionated individual I ended up in an interesting argument on twitter today, as I often do.

My opinion was along the lines that the New Zealand government should stop trying to right the wrongs caused in the past with the Maori tribes and move on, dismantle the Waitangi Tribunal and abolish the racist policy of Maori only seats. (1)

What made the resulting discussion notable, is that it amused me in that trying to justify the opposing opinion as being right and mine being wrong, this statement was sent to me:

"The ONLY thing that's right is an opinion based on a sound knowledge of past reality:history."

Whether it is based on historical truths or not is irrelevant unless it references the past in order to provide backing information to try and convince the other party to agree on your opinion.

My whole side of the discussion was that “yes, bad stuff happened in the past, but to move forwards as a country we should put them behind us”, explicit acknowledging that there HAVE been past wrongs and that my opinion is that we should forget them and move on as a united country.

I don’t mind people disagreeing with my opinion and giving their reasons, even if they still don’t agree after some time, but saying that it’s arrogant and wrong just rubs me the wrong way and changes it from a discussion into a childish argument.

I would also like to point out that it’s an OPINION! You can’t say it’s right or wrong, you can only agree or disagree with it.

(1) The whole issue of the Maori Seats and Waitangi Tribunal is something I’ll leave for another blog post, it’s too complex to go into details here.

Huawei E220 with Fedora 12

In the weekend I upgraded my Libretto U100 to Fedora 12 (from Fedora 9 previously). I was extremely surprised (and happy) to find that everything worked correctly first time with the exception of the docking station (which I shall blog about later). Considering the rarity and uniqueness of this particular machine, it’s an excellent result.

HUAWEI E220 IS A PITA

However I discovered that my Huawei E220 3G Modem (branded as “Vodem” here in NZ) was now failing to work – when trying to connect, NetworkManager would start, the connection would run for a few seconds and then suddenly disconnect. I would also receive a popup saying that sr0 was unable to be mounted.

The 3G modem would then fail to appear in Network Manager and the kernel log showed lots of weird USB errors.

The Huawei E220 is an interesting device, it has both a 3G modem and also a USB “SCSI CDROM” drive which contains drivers for when plugged into a Windows computer. However this dual-device operation has historically caused no end of different problems across various Linux releases.

In Fedora 12, it seems that the “cdrom” (usbstorage) and 3G Modem (usbserial) drivers fight each other – first the usbserial driver works as expected, connects to the network and Network Manager runs OK. However a second later the “cdrom” tries to get mounted and glitches, breaking both drivers and dropping the connection.

SOLUTION

You can’t work around it by trying some of the past workarounds with older Linux releases such as removing the usbstorage module or apply custom vendor & product options to the usbserial module, either workaround will break the newer version of NetworkManager/ModemManager.

Fortunately the fix is relatively simple – we just need to tell the system to ignore the “cdrom” – which we can do by using Udev. Simply create the file /etc/udev/rules.d/20-custom-huawei.rules with the contents of:

# work around dodgy Huawei modem
SUBSYSTEMS=="scsi" ATTRS{vendor}=="HUAWEI", OPTIONS+="ignore_device"

Then re-plug the Huawei and the system will detect both the 3G Modem and the “cdrom”, however the ignore_device option will cause udev to avoid trying to mount the CDROM and therefore permits the 3G modem to work uninterrupted. :-)

Export MySQL database from PHP

As part of the Amberdms Billing System I needed to add the ability to export the entire MySQL database when logged in as an administrator from the application UI.

This feature was desired to prevent any shoddy hosting companies from preventing users from downloading their data from the application – without it, a hosting provider could refuse to provide the database creating effective vendor lock-in for users, even though the software is open source.

There were a couple different approaches I could use:

  • Implement code that reads all the database structure and data rows and writes SQL from that. (this is the phpmyadmin approach)
  • Use mysqldump from the CLI

I chose the latter, since it’s much easier to write and maintain than a SQL generator like phpmyadmin uses, however I came across a few challenges:

  • I needed to supply a username & password to mysqldump – however, doing this via the CLI would expose the password to anyone with shell access to the server (they could run ps aux to see the password used).
  • The databases could be anywhere from 1MB to several hundred, whatever solution was chosen could not require the whole file to be stored in memory.

My approach was to write some code that creates a temporary configuration and export file, then saves the authentication details into the temp file and calls mysqldump and instructs it to use the config file for options.

To provide the file for download, the PHP script then sets the HTTP headers and uses readfile to basically output all the file contents straight to the brower, avoiding any memory issues for the PHP script.

Below is my code, note that there are some support functions used to generate secure, unique temp files as well as perform easier MySQL queries, but it is easy to adapt to whatever framework you are using.

It is important to note that the process that generates your temporary files should make sure the files are readable ONLY by the webserver process, otherwise other users could read the config file and discover the passwords.

/*
	Create temp files for download
*/
$file_config	= file_generate_tmpfile();
$file_export	= file_generate_tmpfile();


/*
	Write authentication information into temp config file 
	this allows us to prevent the exposure of the DB password on the CLI
*/

$fh = fopen($file_config, "w");
fwrite($fh, "[mysqldump]\n");
fwrite($fh, "host=". $config["db_host"] ."\n");
fwrite($fh, "user=". $config["db_user"] ."\n");
fwrite($fh, "password=". $config["db_pass"] ."\n");
fclose($fh);


/*
	Export Database
*/

$dbname = sql_get_singlevalue("SELECT DATABASE() as value");

system("/usr/bin/mysqldump --defaults-file=$file_config $dbname > $file_export");


/*
	Set HTTP headers
*/

$filename = "database_export_". mktime() .".sql";
	
// required for IE, otherwise Content-disposition is ignored
if (ini_get('zlib.output_compression'))
	ini_set('zlib.output_compression', 'Off');

header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers 
header("Content-Type: application/force-download");
	
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");

// tell the browser how big the file is (in bytes)
header("Content-Length: ". filesize($file_export) ."");


/*
	Print out the file contents for browser download
*/
readfile($file_export);


/*
	Cleanup
*/
unlink($file_config);
unlink($file_export);

Feel free to use any of this code royalty-free in your own applications. :-)

Xen on RHEL Low Memory Bug

Sometimes when trying to create new Xen domains, my Xen server will refuse to create the domain, complaining with “Error creating domain: Out of memory. xc_dom_boot_mem_init: can’t allocate low memory for domain”.

This problem is a currently known bug, there are various patches and work arounds being discussed on the Red Hat bug tracker. If you don’t want to rebuild Xen with a patch to try and resolve the issue I found that manually reducing the amount of memory that the host (Domain-0) was consuming would resolve the issue.

You can do this by running (as root):

$ xm mem-set Domain-0 1024M

Set to whatever memory value you want, if your host does nothing other than running Xen for all the VMs, you can set it quite low, I recommend 256MB.

This error only seems to happen on x86_64 servers, according to the bug report the reason was “For each vcpu of xen/ia64, it requires 16M contiguous memory for vhpt, but balloon driver didn’t consider this case when it balloons memory.”

For details, refer to bug 466021 at Red Hat.

Cheddar Bay Exploit

A new 0-day attack on the Linux kernel has just been released by Brad Spengler called the “Chedder Bay Exploit” which exploits a flaw in the Linux 2.6.30+ kernel.

This exploit is interesting, in that the code doesn’t look particularly broken, but when compiled the compiler optimisations causes the compiled code to have a security hole.

For more technical details on this exploit and further news, check the LWN.net article or use the CVE reference CVE-2009-1897.

From my quick review of the exploit, it appears the attack uses Pulseaudio to bypass Selinux security if it is enabled and then performs an attack against the /dev/net/tun device, allowing a standard user to gain root access.

Not having pulseaudio or the tun kernel module loaded should prevent this exploit from working, although I have not yet had sufficient time to test this since I received the alert announcement around 3am NZ time.

The exploit affects the 2.6.30+ kernel releases and also some of the test kernel 2.6.18 kernel releases by Redhat.

However, all production kernel releases for RHEL/CentOS do not appear to be vulnerable since the change that introduced the security exploit had not been backported yet.

In my tests on CentOS 5.3 with kernel 2.6.18-128.1.16.el5xen on i386/xen, I was unable to trigger the exploit.

UPDATE 19th July 2009

I have a correction to make based on feedback from Brad Spengler, the exploit uses Pulseaudio if there is no SELinux present, or if it is in the disabled state.

However, if SELinux is enabled, the exploit uses a vulnerability in SELinux to gain privileges without the need of Pulseaudio – this is a situation where attempting to use SELinux to make yourself more secure actually leads to your system being less secure.

Many thanks to Brad for the explanation.