2009-12-14 20:30:26 PST
So basically I am writing a program and need it to be able to create a new user under a postfix/dovecot server using mysql databases. I know which databases to write to etc. I just can't find out how the password encryption is done. It seems like it is done through postfixadmin as that is how I created the mailboxes. The code I found is as follows:
//
// pacrypt
// Action: Encrypts password based on config settings
// Call: pacrypt (string cleartextpassword)
//
function pacrypt ($pw, $pw_db="")
{
global $CONF;
$password = "";
$salt = "";
if ($CONF['encrypt'] == 'md5crypt')
{
$split_salt = preg_split ('/\$/', $pw_db);
if (isset ($split_salt[2])) $salt = $split_salt[2];
$password = md5crypt ($pw, $salt);
}
if ($CONF['encrypt'] == 'system')
{
if (ereg ("\$1\$", $pw_db))
{
$split_salt = preg_split ('/\$/', $pw_db);
$salt = $split_salt[2];
}
else
{
$salt = substr ($pw_db, 0, 2);
}
$password = crypt ($pw, $salt);
}
if ($CONF['encrypt'] == 'cleartext')
{
$password = $pw;
}
return $password;
}
I found a reference to pacrypt in the create-mailbox.php file. It seems this function is what creates the encrypted password. I am writing my program in python and can't figure out a way to replicate the encryption method shown here. help would be much appreciated. Even if its just pointing me in the right direction.
Thanks in advance.