merging passwd and shadow files

I wrote a Perl script to merge /etc/passwd and /etc/shadow files from two hosts

In the words of Elizabeth “Now you have two problems?”

See below. Sadly wordpress doesn’t do.. well.. any job of indenting. And in case you’re wondering, I’ve munged the passwd hash in the file :P

#!/usr/bin/perl
open PASSWD, "</etc/passwd" or die $!;
open OPASSWD, "<passwd.other" or die $!;
open OSHADOW, "<shadow.other" or die $!;
# Read this hosts /etc/passwd into memory
# nfsnobody:x:4294967294:4294967294:Anonymous NFS User:/var/lib/nfs:/dev/null
while ( <PASSWD> ) {
chomp;
my ($uid,$junkpass,$pruid,$pguid,$officename,$homedir,$shell) = split(/:/,$_,7);
$THISHOST{$uid}{'junkpass'} = $junkpass;
$THISHOST{$uid}{'pruid'} = $pruid;
$THISHOST{$uid}{'pguid'} = $pguid;
$THISHOST{$uid}{'officename'} = $officename;
$THISHOST{$uid}{'homedir'} = $homedir;
$THISHOST{$uid}{'shell'} = $shell;
}
close PASSWD;
# Read other machine's /etc/passwd into memory
while (<OPASSWD>) {
chomp;
my ($uid,$junkpass,$pruid,$pguid,$officename,$homedir,$shell) = split(/:/,$_,7);
$THATHOST{$uid}{'junkpass'} = $junkpass;
$THATHOST{$uid}{'pruid'} = $pruid;
$THATHOST{$uid}{'pguid'} = $pguid;
$THATHOST{$uid}{'officename'} = $officename;
$THATHOST{$uid}{'homedir'} = $homedir;
$THATHOST{$uid}{'shell'} = $shell;
}
close OPASSWD;
# Read other machine's /etc/shadow into memory
# aua:$1$6LzssYvL$Wqs94Dv/ZSkuGl0LXQpKb1:13392:0:99999:7:::
while (<OSHADOW>) {
chomp;
my ($uid,$passstring) = split(/:/,$_,2);
$THATSHADOW{$uid} = $passstring;
}
close OSHADOW;
# Check for missing accounts
foreach $account (sort keys %THATHOST) {
if (!(defined($THISHOST{$account}))) {
print "Missing $account\n";
$passwdbuf = $passwdbuf . "$account:$THATHOST{$account}{junkpass}:$THATHOST{$account}{pruid}:$THATHOST{$account}{pguid}:$THATHOST{$account}{officename}:$THATHOST{$account}{homedir}:$THATHOST{$account}{shell}\n";
$shadowbuf = $shadowbuf . "$account:$THATSHADOW{$account}\n";
} else {
print "$account: $THISHOST{$account}{pruid} = $THATHOST{$account}{pruid}\n";
}
if ((defined($THISHOST{$account})) && ($THISHOST{$account}{pruid} ne $THATHOST{$account}{pruid})) {
$uiderrors = $uiderrors . "$account : THISHOST:$THISHOST{$account}{pruid} THATHOST:$THATHOST{$account}{pruid}\n";
}
}
# Output missing accounts for /etc/passwd
print "------------------\n";
print "Add to /etc/passwd\n";
print "$passwdbuf\n";
# Output missing accounts for /etc/shadow
print "------------------\n";
print "Add to /etc/shadow\n";
print "$shadowbuf\n";
# UID Mis-matches
print "------------------\n";
print "UID Mis-matches\n";
print "$uiderrors\n";

For @JuliaGillard

Dear Prime Minister Gillard,

To begin, I congratulate you on your commencement as new Prime Minister of Australia. My wife and I are Australian Citizens currently living overseas in Canada and working as IT consultants and watched the change unfold with great interest.

I write to you in agreement with the Australian Government’s continued efforts to prevent child abuse and distribution of images and other depictions of the same on the Internet. I believe that the more resources allocated to law enforcement, the better the outcomes.

However, I am concerned that your government may be looking to continue the mistake of the Kevin Rudd-lead government in attempting to implement an Internet Filter to attempt to prevent access to this material.

In much the same way that China’s internet filter only prevents casual browsing of material deemed subversive to the state, an Internet filter in Australia for indecent and illegal content will only prevent casual browsing of such material. Everything I’ve read seems to suggest there no such thing as casual browsing of such material.

I also know that the government of China has spent a lot of money and effort in attempting to put their filter in place, believing it is necessary to maintain public order. If the Chinese filter can’t stop the flow of information to protect the whole country, why is it the view of the Government of Australia that in a free society they can do a better job of it?

Therefore in fact, an Internet filter will achieve nothing, at the expense of the speed, reliability and privacy of every Australian using the Internet. Further, it will put a framework in place for future governments of Australia to attempt to filter out other “subversive” content. The Internet cannot be censored. Material can be removed at its source, and I commend the AFP on their efforts to do so.

I urge your government to drop these plans for wasting money on a totally ineffective Internet filter, and instead divert that money to law enforcement.

Yours Sincerely,
@theducks

Oh Microsoft..

Came across an interesting problem today. I resized a VMDK of a Windows Server 2008 R2 virtual machine today, then ran gparted, and when I rebooted.. it was no good.

In Windows’ defence, I made some mistakes. I told gparted to align to cylinder boundaries, which the original partition wasn’t, and I didn’t let the VM shut down properly (it had rebooted, so I figure it would be ok to do a virtual power down.. oops). I also didn’t take a vmware snapshot beforehand.

But being the nice person I am and not wanting to waste one of my co-worker’s days work on it by reverting to backups, I thought I’d give it a bit of a go at fixing it.

First step was manually un-aligning it back to the geometry I had before, which I did using the command line parted in “sector” unit mode. Then I tried booting.. and no luck.

I did some reading, and had got to reading about bcdedit, the new tool in vista/2008 for editing boot parameters. It’s pretty hardcore.. I tried resetting it, and got slightly different errors, but it still didn’t work.

I did some more googling on the error, and found someone describing how to fix the same problem with Vista. You just pop in the system install disk and follow some prompts, and it’ll automatically repair it. Cool! I thought, I’ll just put in the Win2008R2 DVD image, and it’ll do the same thing.

No dice.

Then I thought.. I wonder what will happen if I boot it from a Vista install DVD, they’re close enough? And blow me down, it worked. So there we go – the solution to a Windows 2008 R2 problem was to use the Windows Vista desktop install DVD.

Only thing left to do was let it shut down gracefully, then run ntfsresize, and it all seems to be working.

“Can I take good pictures with my point and shoot digital camera?”

A simple question asked by an online acquaintance of Elizabeth. The answer is: it depends on what you think makes a good picture.

Photography as an art is about making an image of a scene in such a way that it evokes an strong emotional response from the viewer. There are many ways to achieve this, and a point and shoot camera need not stop you from being able to do so.

For example, this photo of a passionfruit is one of my favourite photos I have ever taken. Partially, it’s because I like passionfruit, but putting that aside, it has good lighting, sharp focus, nice colours, and even a nice background blur. And I took it in December 2001 with a camera I had owned for less than 48 hours, that wasn’t a digital SLR. My only criticism of it is that it is in 4:3 ratio, not 2:3 ratio. Even if the camera doesn’t support 2:3 ratio photographs, try imagining the top and bottom of the photo will be cut off, and you can do it in post production..

I took 6000 photos with that Canon G2 over the next 5 years (even though I paid $1990 for the camera, I think I got my monies worth, and it’s still going strong with my Dad), and eventually discovered it had one weakness – really really really poor handling in low light – it would put about 14 vertical bars through any short shutter speed low light situation. Back in 2001 when I bought that camera, there were a lot of crappy cameras on the market, even from companies like Sony. But today, in the right conditions, any modern name brand digital camera can take a great photo. The question is, what is required to make a nice image like that one?

The easy answer is light, and lots of it. Either natural (preferred) or from a flash, or from an external light. The quality of the colour is based on the type of light. Natural light is very wide bandwidth, so is nice for photography. Flashes are also pretty wide bandwidth, as are studio lights. Problem comes from home lighting fixtures, especially compact fluorescent ones, which are somewhat narrower, leading to colour reproduction problems. You know how some parking lots have lights that make everything look yellow? Well, think of poor quality lighting like that – the human eye + brain generally doesn’t notice the smaller gamut, but the camera will, and may try to correct colours, with varying levels of success.

Flashes are nice, but not generally pointed directly at what you want to photograph. This is where point and shoot cameras have a problem, since their flashes generally point straight ahead. You want the light to be softened, and coming from all directions (maybe pointed in one surface specifically, but you will often still want it in other places). The way to do that is by using bounce flash. My usual trick is the reverse ceiling bounce with my digital SLR + external flash. Point the flash backwards and upwards over your head, and towards a white surface. The light reflected will be diffused, and look nice. Like this one.

Some non digital SLR cameras take external flashes. If nothing else, if you want to take photos indoors, I would recommend getting one of those, and an external flash. Be aware that the flash may cost as much as the camera, but it’ll be worth it, and still probably cheaper than buying a new digital SLR.

So, light = good, and good light = good colour.

Focus is generally pretty easy to deal with – every camera or lens will have a minimum focus distance stated somewhere. Do not try to photograph closer than that, and the camera will probably take care of it ok. In my camera, I have it set to auto-focus on the centre point only. I focus by holding the shutter button down part way till it focuses and gets light levels right, then while still holding the button down, recompose. On the subject of composition, the rule of thirds is pretty twee, but not a bad starting point.

Background blur (or bokeh) is a little harder to manage, and is another area where digital SLRs can help. Camera lenses have a depth of field, or how deep something is in focus.. closer or further away and it’ll be blurry. This is a function of aperture and how far away from the subject you are. Lower aperture number = physically larger aperture = smaller depth of field. Physically larger aperture = more light gets into camera, and as we recall, light is good. So you can do it two ways.. either have a low aperture lens, or move the background further away from the object (or vis-a-versa).

Point and shoot cameras will often have higher apertures, meaning bigger depth of field, which makes it easy to get everything in focus, which is the first thing many people will notice about a photo. They’re also easy to build, since the size of the internal diameter of the lens can be smaller. For example, Elizabeth’s P&S camera has an aperture range of 3.2 – 5.8, which isn’t bad, but isn’t great either. My nifty-50 lens has an aperture of 1.8, which means it can take photos in reasonably low light. For insane sums, you can buy 1.0 and 0.95 lenses, which combined with a good camera, will let you take photographs using candles as lighting.

You can make up for a camera that is less sensitive to light by increasing the shutter speed, but past a certain point the photos will blur because the camera or the subject will move. A longer shutter speed also won’t help with aperture or background blur. A tripod can help here if it’s going to be the camera that moves, but not if it’s the subject. To make up for cameras moving, some point and shoot cameras and some digital SLRs have image stabilisation, which uses gyroscopes or adaptive optics or both to keep the image fairly still even when the camera moves. Then you just need to worry about the subject moving..

Which gets the to crux of the question – digital SLRs vs point and shoot cameras. You for the most part, get what you pay for. How much do you want to pay and what do you want to get? Find the intersecting point, and buy that. If you can’t find that intersection, change your price point or your desires, or wait a while.

What makes a camera cost what it does – what’s the difference between a $20,000 Hasselblag H4D medium format camera, and a $120 Canon A480? Sensor size is one of the keys. Bigger sensors = larger pixels = more light gathered per pixel per second = less noise. They often try to express this as ISO light sensitivity. Small sensors make up for this by running more electricity through the sensor to detect light, but at the trade off of having a more grainy image. They deal with the grainy image by having in-camera noise reduction, that essentially blurs the noise away if it’s too bad, or by taking the photo with a high enough megapixel count that when printed or scaled down, you’re not going to notice it. A bigger megapixel number, like the megahertz myth of computers, gives an easy number for the uneducated to compare and base decisions on, but it’s not that important. As long as it’s over 6MP and you don’t want to print giant posters, it’s all good.

The other cost input is lenses. Point and shoots have small non-interchangeable lenses which don’t let in much light, but they’re cheap to make. Digital SLR lenses are bigger, heavier and thus more expensive to make and distribute, but they make some that let in a lot of light, so they have that going for them. Also, being inter-changable, they don’t have to be a "jack of all trades, master of none", but you can buy digital SLR lenses that are. 

So what should you buy? Digital SLRs are big and bulky, and relatively expensive, but it’s easier to take nice pictures with them. Point and shoots are cheap and can take nice pictures, but it’s harder, and you will eventually reach a point where your creativity will be limited and there’s nothing you can do to help. If you want a digital SLR but have sticker shock, consider secondhand ones. Anything from 2006 onwards from Canon or Nikon is a good option. Take a photo of a white wall and look at it up close in an image viewer – see if there is any dust or dead or bright pixels. You’ll know them when you see them. Even those don’t make it a walk away deal, just something to negotiate on. 

If you can’t buy a digital SLR, but you care about making nice images, buy a Canon G11
. It’s a point and shoot with a lot of features from a digital SLR, including support for external flashes. It has a larger than average sensor (and in the most recent revision, grom G10 to G11, they actually decreased the megapixel count, to make a better sensor), a larger aperture range (2.8 – 4.5), and it doesn’t cost the earth (like my Canon G2 did back in 2001..). 

So that’s my thoughts on the question “Can I take good pictures with my point and shoot digital camera?” .. what are yours?

Vroom!

Some of you may not have seen this on Facebook/twitter, but after much discussion and thinking about moving, etc, we bought a car – a 2005 Toyota Prius – in white.

We’ve done 400kms since thursday on it. The novelty of having a car is still new. It’s got 4.9L/100KM (48mpg) so far, so my daily commute of 33.2km will use ~1.6L of fuel, which at current rates is $1.82 per day.. so 21 days work per month makes it $38.26 .. plus $70 for a parking pass… and.. wait for it.. $370/*month* for insurance and registration (to be reduced to ~$230 when I get some paperwork from SGIO).

Before I go on about the car.. let me rant about the insurance/rego some more. BC has this company called ICBC. It’s government owned, but run as a corporation with an independent board of directors, so no ministerial oversight. Nice work if you can get it huh? They do all driver licensing, car registration and compulsory third-party insurance, and make ~$400 million profit per year. Yeah, thanks. Cost of doing business right?

Anyway, back to the car. It used to belong to Telus, which means I have a safe in the back of it (I guess they used it for laptops?) and a Telus branded first aid kit. It also had a lot of stone chips on the paintwork, a broken cargo net, and 143k KMs (89k miles) on the clock. All of this combined to make it the cheapest Prius I’ve seen for sale in Vancouver in the last 3 months – $9900.

So far we’ve repaired the cargo net (with some nifty black plastic S-hooks), touched up the paint chips with some Toyota matching paint, and bought a new tail light assembly for it off eBay.

Why a new taillight assembly you may ask? Well, I misjudged the location of a pillar while reversing into our parking stall here at the apartment block. Ewps. Mister Sheen Magic Eraser got the blue paint off the bumper, though some scratches remain, and there’s a small amount of panel damage that I’ll probably need to get professionally fixed, but once we get the new taillight installed, it’ll look good enough ;)

Anyway, back to how we’ve racked up 400KMs so far. I picked Elizabeth up from a write-in, saving her well over an hour of public transport, we went to North Vancouver and had delicious curry veggie pizza, we went to Finn Slough, went to Steveston, did some exploring of Richmond (found a street with almost every major religion/belief system of the area representing – Sikhism, Buddism, Christianity, Islam, Vedic..), and did our shopping.

The Angler-fish

I love this guy’s writing style:

This is why, when you’re heartbroken, you should never listen to people who try to console you with the maxim ‘there are plenty of fish in the sea.’ While this is technically true, you should also be aware that Deep Sea Anglerfish (and, for that matter, barracudas and deadly venomous Stonefish) are among those other fish in the sea. And as long as we’re on the subject of Deep Sea Anglerfish, you can also now confidently ignore ‘Don’t be afraid of the dark.’ Also, on a completely unrelated note, ‘Lead, follow or get out of the way’ is kind of pointless too.

From http://animalreview.wordpress.com/2009/10/12/deep-sea-anglerfish/

Samsung BD-P1600 Problems..

We bought a Blu-ray player a few weeks ago, and it had been working fine until we did a firmware upgrade / plugged it into the network.. when it became unresponsive. Did some digging and found it behaves terribly when it’s connected via HDMI to a non-Samsung TV with CEC-Link (aka vieralink, anynet, etc). Turned that off and it works fine.

Hope this helps someone on the internets.

(also *cough* we crossflashed it to the Singapore firmware which lets you set it into region-free for DVD :)