Difference between revisions of "Password Migration"

m (Migrating Users Password from Postfix Admin)
Line 11: Line 11:
// Trivial bug fixed by Luca G. on 18-01-2009
// Trivial bug fixed by Luca G. on 18-01-2009

Revision as of 17:20, 30 July 2009

Migrating Users Password from Postfix Admin

Save this script as something.php, make chmod +x something.php and run. Script will export all email accounts into designated file.


// Postfix.admin to Zimbra import
// Created by Jarosław Czarniak on 26-10-2008
// Trivial bug fixed by Luca G. on 18-01-2009


$tabl="mailbox"; //table

echo "Usage: as \"zimbra\" user on destination server:\n";
echo "# sh ./exported.sh\n\n";
echo "";

$mydb = mysql_connect('localhost',$user, $pass) or die ('Błąd połączenia z serwerem');
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");

$query = "SELECT username,password,name,maildir,quota,domain FROM ".$tabl;
$dane = mysql_query($query) or die ('Błąd podczas zapytania do bazy1'.mysql_error());

$handle = fopen($file, "w");

while ($row = mysql_fetch_array($dane, MYSQL_NUM))
    $StringData = "zmprov ca ".$row[0]." dsfs123hsdyfgbsdgfbsd displayName '".$row[2]."'\n";
    fwrite($handle, $StringData);
    $StringData = "zmprov ma ".$row[0]." userPassword '{crypt}".$row[1]."'"."\n";
    fwrite($handle, $StringData);


Migrating User Password from Shadow Password to Zimbra

Basically we will use the hash password from /etc/shadow. Get the hash values in between the first and second colon only. Eg:


Then run this as user zimbra.

zmprov ma user1@domain userPassword '{crypt}$1$MWAOIgPB$skcX.nKYV9JSctTR60uat/'

A simple batch script to migrate bulk shadow password into zimbra password as below:

# Usage: as root   # ./shadow2zm.pl /etc/shadow > shadow.zm
#        as zimbra # zmprov < shadow.zm


while(<>) {
    my ($uname,$pass) = split(/:/);

    print qq{zmprov ma $uname\@$domain userPassword '{crypt}$pass'\n};
    print qq{\n};

Credit to bewley from this forum post


In some cases above perl script doesn't work very well. And if user doesn't already exist you will get en error. My script will import and create all users from shadow file (with exception of system accounts).


# Shadow to Zimbra import
# Created by Jarosław Czarniak on 26-10-2008

echo "Usage: as \"zimbra\" user on destination server"
echo "# zmprov < shadow.file"

domain="jarsat.pl"  # change to your domain!
echo ''>$file

for linia in `cat /etc/shadow`
    user=`echo $linia|cut -f1 -d":"`
    pass=`echo $linia|cut -f2 -d":"`

    if [ "$pass" != "*" ]
        if [ "$pass" != "!" ]
            echo "zmprov ca $user@$domain temppasswordQAZXSW displayName $user">>$file
            echo "zmprov ma $user@$domain userPassword '{crypt}$pass'">>$file

echo "$x accounts exported to \"$PWD/$file\""

sleep 5
Jump to: navigation, search