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