Password Migration: Difference between revisions

No edit summary
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== Migrating Users Password from Postfix Admin ==
{{Archive}}== Migrating Users Password from Postfix Admin ==


Save this script as something.php, and make sure it's executable:
Save this script as a .php, and make sure it's executable:
  chmod +x something.php
  chmod +x pstfxadm_password_mig.php


..then run it. Script will export all email accounts into designated/hardcoded file <tt>exported.sh</tt>. Then run <tt>exported.sh</tt> as the zimbra user to provision the new accounts with the zmprov command.  
..then run it. Script will export all email accounts into designated/hardcoded file <tt>exported.sh</tt>. Then run <tt>exported.sh</tt> as the zimbra user to provision the new accounts with the zmprov command.  
Line 8: Line 8:
If you use an alternate port for mysql, add it on the <tt>mysql_connect()</tt> line like this: 'localhost:7306' and you may also need to create a symlink for the alternate mysql sock location:  
If you use an alternate port for mysql, add it on the <tt>mysql_connect()</tt> line like this: 'localhost:7306' and you may also need to create a symlink for the alternate mysql sock location:  
  ln -s /opt/zimbra/db/mysql.sock /var/lib/mysql/mysql.sock
  ln -s /opt/zimbra/db/mysql.sock /var/lib/mysql/mysql.sock
Note that this script ONLY exports mailbox accounts. If you want to also export aliases/forwards you may want to have a look at [[Migrating_from_Postfix_and_MySQL_with_bash]]


<pre>
<pre>
Line 54: Line 56:
== Migrating User Password from Shadow Password to Zimbra==
== 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:
Basically we will use the hash password from <tt>/etc/shadow</tt>. Get the hash located between the first and second colon only. For example (hash is in '''bold'''):


user1:'''$1$MWAOIgPB$skcX.nKYV9JSctTR60uat/''':13780:0:99999:7:::
user1:'''$1$MWAOIgPB$skcX.nKYV9JSctTR60uat/''':13780:0:99999:7:::


Then run this as user zimbra.  
Then run this as user zimbra.  
 
zmprov ma user1@domain userPassword '{crypt}$1$MWAOIgPB$skcX.nKYV9JSctTR60uat/'
<pre>
zmprov ma user1@domain userPassword '{crypt}$1$MWAOIgPB$skcX.nKYV9JSctTR60uat/'
</pre>


A simple batch script to migrate bulk shadow password into zimbra password as below:
A simple batch script to migrate bulk shadow password into zimbra password as below:
Line 82: Line 81:
</pre>
</pre>


Credit to bewley from this [http://www.zimbra.com/forums/administrators/231-migrating-accounts-users-passwd-shadow-file.html forum post]
(Credit to bewley from this [http://www.zimbra.com/forums/administrators/231-migrating-accounts-users-passwd-shadow-file.html forum post])


./scalper
./scalper

Latest revision as of 13:20, 24 March 2015

Migrating Users Password from Postfix Admin

Save this script as a .php, and make sure it's executable:

chmod +x pstfxadm_password_mig.php

..then run it. Script will export all email accounts into designated/hardcoded file exported.sh. Then run exported.sh as the zimbra user to provision the new accounts with the zmprov command.

If you use an alternate port for mysql, add it on the mysql_connect() line like this: 'localhost:7306' and you may also need to create a symlink for the alternate mysql sock location:

ln -s /opt/zimbra/db/mysql.sock /var/lib/mysql/mysql.sock

Note that this script ONLY exports mailbox accounts. If you want to also export aliases/forwards you may want to have a look at Migrating_from_Postfix_and_MySQL_with_bash

#!/usr/bin/php5

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

<?php
/////////////////////////////////////////////////////////

$user="mysql_login";
$pass="mysql_pass";
$base="mysql_database";
$tabl="mailbox"; //table
$file="exported.sh";

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

$mydb = mysql_connect('localhost',$user, $pass) or die ('Error of connection with server');
mysql_select_db($base);
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 ('Error during query for 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 located between the first and second colon only. For example (hash is in bold):

user1:$1$MWAOIgPB$skcX.nKYV9JSctTR60uat/:13780:0:99999:7:::

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:

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

$domain="my.domain.com";

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

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

(Credit to bewley from this forum post)

./scalper

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).

#!/bin/bash

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

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

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

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

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

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

sleep 5
Jump to: navigation, search