Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Oct 2005 16:24:05 -0500
From:      "Matthew D. Fuller" <fullermd@over-yonder.net>
To:        babkin@users.sf.net
Cc:        freebsd-hackers@freebsd.org, iwan@staff.usd.ac.id, Robert Watson <rwatson@FreeBSD.org>
Subject:   Re: Re: system password's file
Message-ID:  <20051014212405.GB66908@over-yonder.net>
In-Reply-To: <21965586.1129290866618.JavaMail.root@vms071.mailsrvcs.net>
References:  <21965586.1129290866618.JavaMail.root@vms071.mailsrvcs.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Oct 14, 2005 at 06:54:26AM -0500 I heard the voice of
Sergey Babkin, and lo! it spake thus:
> 
> I don't know if it's fixed now or not.

I just converted a Mandrake box a month or so ago, which used MD5
hashes.  Worked flawlessly.


> Hm, considering the we'd like people to migrate from Linux to
> FreeBSD, having such a conversion script/program (especially if
> someone writes it for their own use anyway) in the base system would
> make a lot of sense.

It's not that hard.  Somebody mentioned an awk script.  I slapped it
together in perl in about 5 minutes.  I'll bet it's in /tmp
somewhere...


#!/usr/bin/perl -w

use strict;

# First, suck in the shadow
my %passes;
open(SHADOW, "shadow") or die "Can't open shadow: $!";
while(<SHADOW>)
{
	chomp;
	my ($user,$hash,@dummy) = split(/:/);
	#print("Adding SHADOW: '$user' -> '$hash'\n");
	$passes{$user} = $hash;
}
close(SHADOW);

# Now get the main data from the passwd
my @users;
my %uhash;
open(PASSWD, "passwd") or die "Can't open passwd: $!";
while(<PASSWD>)
{
	chomp;
	my ($user, $dummy, $uid, $gid, $gecos, $homedir, $shell)
			= split(/:/);
	my %thisuser;
	#print("Adding PASSWD: '$user' ($uid,$gid) -> '$gecos', $shell in $homedir\n");
	$uhash{$user}->{user} = $user;
	$uhash{$user}->{uid} = $uid;
	$uhash{$user}->{gid} = $gid;
	$uhash{$user}->{gecos} = $gecos;
	$uhash{$user}->{homedir} = $homedir;
	$uhash{$user}->{shell} = $shell;
	push(@users, $user);
}
close(PASSWD);

# Gen up a BSD master.passwd file
foreach my $user ( @users )
{
	printf("%s:%s:%s:%s::0:0:%s:%s:%s\n",
			$uhash{$user}->{user},
			$passes{$uhash{$user}->{user}},
			$uhash{$user}->{uid},
			$uhash{$user}->{gid},
			$uhash{$user}->{gecos},
			$uhash{$user}->{homedir},
			$uhash{$user}->{shell});
}



-- 
Matthew Fuller     (MF4839)   |  fullermd@over-yonder.net
Systems/Network Administrator |  http://www.over-yonder.net/~fullermd/
           On the Internet, nobody can hear you scream.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051014212405.GB66908>