<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>theducks.org &#187; Linux</title>
	<atom:link href="http://theducks.org/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://theducks.org</link>
	<description>geeky rambling</description>
	<lastBuildDate>Tue, 24 Jan 2012 02:51:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-beta1</generator>
		<item>
		<title>merging passwd and shadow files</title>
		<link>http://theducks.org/2010/07/merging-passwd-and-shadow-files/</link>
		<comments>http://theducks.org/2010/07/merging-passwd-and-shadow-files/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 00:47:03 +0000</pubDate>
		<dc:creator>alex</dc:creator>
				<category><![CDATA[Gibbering]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://theducks.org/?p=146</guid>
		<description><![CDATA[I wrote a Perl script to merge /etc/passwd and /etc/shadow files from two hosts In the words of Elizabeth &#8220;Now you have two problems?&#8221; See below. Sadly wordpress doesn&#8217;t do.. well.. any job of indenting. And in case you&#8217;re wondering, I&#8217;ve munged the passwd hash in the file :P #!/usr/bin/perl open PASSWD, "&#60;/etc/passwd" or die [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a Perl script to merge /etc/passwd and /etc/shadow files from two hosts</p>
<p>In the words of Elizabeth &#8220;Now you have two problems?&#8221;</p>
<p>See below. Sadly wordpress doesn&#8217;t do.. well.. any job of indenting. And in case you&#8217;re wondering, I&#8217;ve munged the passwd hash in the file :P</p>
<p><code> </code></p>
<p><code></p>
<div id="_mcePaste">#!/usr/bin/perl</div>
<div id="_mcePaste">open PASSWD, "&lt;/etc/passwd" or die $!;</div>
<div id="_mcePaste">open OPASSWD, "&lt;passwd.other" or die $!;</div>
<div id="_mcePaste">open OSHADOW, "&lt;shadow.other" or die $!;</div>
<div id="_mcePaste"># Read this hosts /etc/passwd into memory</div>
<div id="_mcePaste"># nfsnobody:x:4294967294:4294967294:Anonymous NFS User:/var/lib/nfs:/dev/null</div>
<div id="_mcePaste">while ( &lt;PASSWD&gt; ) {</div>
<div id="_mcePaste">chomp;</div>
<div id="_mcePaste">my ($uid,$junkpass,$pruid,$pguid,$officename,$homedir,$shell) = split(/:/,$_,7);</div>
<div id="_mcePaste">$THISHOST{$uid}{'junkpass'} = $junkpass;</div>
<div id="_mcePaste">$THISHOST{$uid}{'pruid'} = $pruid;</div>
<div id="_mcePaste">$THISHOST{$uid}{'pguid'} = $pguid;</div>
<div id="_mcePaste">$THISHOST{$uid}{'officename'} = $officename;</div>
<div id="_mcePaste">$THISHOST{$uid}{'homedir'} = $homedir;</div>
<div id="_mcePaste">$THISHOST{$uid}{'shell'} = $shell;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">close PASSWD;</div>
<div id="_mcePaste"># Read other machine's /etc/passwd into memory</div>
<div id="_mcePaste">while (&lt;OPASSWD&gt;) {</div>
<div id="_mcePaste">chomp;</div>
<div id="_mcePaste">my ($uid,$junkpass,$pruid,$pguid,$officename,$homedir,$shell) = split(/:/,$_,7);</div>
<div id="_mcePaste">$THATHOST{$uid}{'junkpass'} = $junkpass;</div>
<div id="_mcePaste">$THATHOST{$uid}{'pruid'} = $pruid;</div>
<div id="_mcePaste">$THATHOST{$uid}{'pguid'} = $pguid;</div>
<div id="_mcePaste">$THATHOST{$uid}{'officename'} = $officename;</div>
<div id="_mcePaste">$THATHOST{$uid}{'homedir'} = $homedir;</div>
<div id="_mcePaste">$THATHOST{$uid}{'shell'} = $shell;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">close OPASSWD;</div>
<div id="_mcePaste"># Read other machine's /etc/shadow into memory</div>
<div id="_mcePaste"># aua:$1$6LzssYvL$Wqs94Dv/ZSkuGl0LXQpKb1:13392:0:99999:7:::</div>
<div id="_mcePaste">while (&lt;OSHADOW&gt;) {</div>
<div id="_mcePaste">chomp;</div>
<div id="_mcePaste">my ($uid,$passstring) = split(/:/,$_,2);</div>
<div id="_mcePaste">$THATSHADOW{$uid} = $passstring;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">close OSHADOW;</div>
<div id="_mcePaste"># Check for missing accounts</div>
<div id="_mcePaste">foreach $account (sort keys %THATHOST) {</div>
<div id="_mcePaste">if (!(defined($THISHOST{$account}))) {</div>
<div id="_mcePaste">print "Missing $account\n";</div>
<div id="_mcePaste">$passwdbuf = $passwdbuf . "$account:$THATHOST{$account}{junkpass}:$THATHOST{$account}{pruid}:$THATHOST{$account}{pguid}:$THATHOST{$account}{officename}:$THATHOST{$account}{homedir}:$THATHOST{$account}{shell}\n";</div>
<div id="_mcePaste">$shadowbuf = $shadowbuf . "$account:$THATSHADOW{$account}\n";</div>
<div id="_mcePaste">} else {</div>
<div id="_mcePaste">print "$account: $THISHOST{$account}{pruid} = $THATHOST{$account}{pruid}\n";</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">if ((defined($THISHOST{$account})) &amp;&amp; ($THISHOST{$account}{pruid} ne $THATHOST{$account}{pruid})) {</div>
<div id="_mcePaste">$uiderrors = $uiderrors . "$account : THISHOST:$THISHOST{$account}{pruid} THATHOST:$THATHOST{$account}{pruid}\n";</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste"># Output missing accounts for /etc/passwd</div>
<div id="_mcePaste">print "------------------\n";</div>
<div id="_mcePaste">print "Add to /etc/passwd\n";</div>
<div id="_mcePaste">print "$passwdbuf\n";</div>
<div id="_mcePaste"># Output missing accounts for /etc/shadow</div>
<div id="_mcePaste">print "------------------\n";</div>
<div id="_mcePaste">print "Add to /etc/shadow\n";</div>
<div id="_mcePaste">print "$shadowbuf\n";</div>
<div id="_mcePaste"># UID Mis-matches</div>
<div id="_mcePaste">print "------------------\n";</div>
<div id="_mcePaste">print "UID Mis-matches\n";</div>
<div id="_mcePaste">print "$uiderrors\n";</div>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://theducks.org/2010/07/merging-passwd-and-shadow-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

