Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Apr 1996 15:53:13 -0600 (MDT)
From:      Dave Andersen <angio@aros.net>
To:        jvissers@monet.telebyte.nl (Jos Vissers)
Cc:        freebsd-isp@FreeBSD.ORG
Subject:   Re: Converting Linux password files to FreeBSD master.passwd
Message-ID:  <199604152153.PAA08093@shell.aros.net>
In-Reply-To: <199604151355.PAA08308@monet.telebyte.nl> from Jos Vissers at "Apr 15, 96 03:55:22 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
Lo and behold, Jos Vissers once said:
> Hello,
> 
> We are converting from Linux to FreeBSD and need to merge the
> Linux passwd and shadow files to a bsd master.passwd file.
> Does anybody know of an existing script to do this?

  If you're using the Linux shadow-mk package, it comes with a program 
called "pwunconv" which will do the trick for you.

   One caveat:  It's a horridly slow program.  In fact, it's actually a 
bit worse than that.  It does a "getspwnam()" on every entry in the 
passwd file, so it's a (number of entries)^2 kind of thing.

   Attached is a perl program which will do exactly the same thing in 
about 1/100th of the time, quite literally.  Sorry about the huge disclaimer.

    Dave Andersen

-- 
angio@aros.net                Complete virtual hosting and business-oriented
system administration         Internet services.  (WWW, FTP, email)
http://www.aros.net/          http://www.aros.net/about/virtual
  "There are only two industries that refer to thier customers as 'users'."

-------- script ----------
#!/usr/bin/perl
##

#****************************************************************************
# This script is copyright (C) 1996 by David G. Andersen
# All rights reserved.
# This information is subject to change without notice and does not 
# represent a commitment on the part of David G. Andersen
# This software is furnished under a license and a nondisclosure agreement.
# This software may be used or copied only in accordance with the terms of
# this agreement.  It is against Federal Law to copy this software on magnetic
# tape, disk, or any other medium for any purpose other than the purchaser's
# use.  David G. Andersen makes no warranty of any kind, expressed or implied,
# with regard to these programs or documentation.  David G. Andersen
# shall not be liable in any event for incidental or consequential 
# damages in connection with, or arising out of, the furnishing, performance,
# or use of these programs. 
#****************************************************************************/


$shadow = "/etc/shadow";
$passwd = "/etc/passwd";
$output = "bsd-passwd";

umask 077;

open(SHADOW, $shadow) || die "Could not open shadow file\n";
while (<SHADOW>) {
        ($name, $enc) = split(/:/);
        $PASS{$name} = $enc;
}


close(SHADOW);

open(PASSWD, $passwd) || die "Could not open passwd file\n";
open(OUT, ">$output") || die "Could not open output file\n";

while (<PASSWD>) {
        chop;
        ($name, $blah, $uid, $gid, $gecos, $homedir, $shell) = split(/:/);
        printf(OUT "%s:%s:%d:%d:%s:%s:%s\n",
                $name, $PASS{$name}, $uid, $gid, $gecos, $homedir, $shell);
}




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