本文主要是介绍为Postfix增加验证模块,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.创建数据库和表:
create database postfix;
create table users(id int(11) NOT NULL primary key AUTO_INCREMENT,username varchar(30) not null,password varchar(30) not null);
create user postfix@localhost identified by '*';
grant all privileges on postfix.* to postfix@localhost identified by '*';
2.Cyrus SASL的配置文件smtpd.conf 如下:
pwcheck_method: auxprop
auxprop_plugin: sql
mech_list: PLAIN LOGIN
log_level: 3
allow_plaintext: true
sql_engine: mysql
sql_hostnames: 127.0.0.1
sql_user:postfix
sql_passwd:*
sql_database:postfix
sql_select: SELECT password FROM users WHERE username='%u';
参考自:http://www.postfix.org/SASL_README.html#auxprop_sql
3.Postfix的配置文件main.cf中加入对Cyrus SASL的支持,如下:
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining, reject_unauth_destination, permit
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_banner = Welcome to our $myhostname ESMTP, Warning:Versionnot Available!
4.在create.php中加入以下内容:
最开始加入以下变量定义:
$mysql_server_name='localhost';
$mysql_username='postfix';
$mysql_password='*';
$mysql_database='postfix';
在表示用户创建成功的if($userid) 后边加入以下语句:
$user=$params['username'];
$pwd=$params['password'];
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);
if (!$conn) {
error_log("mysql connected error!");
}
mysql_select_db($mysql_database,$conn);
$sql="insert into users (username,password) values ('$user','$pwd')";
if (!mysql_query($sql,$conn))
{
error_log('Error: ' . mysql_error());
}
mysql_close($conn);
5.在edit.php中加入以下内容:
最开始加入以下变量定义:
$mysql_server_name='localhost';
$mysql_username='postfix';
$mysql_password='*';
$mysql_database='postfix';
在表示用户编辑成功的if($result) 后边加入以下语句:
if($params['password']!=''){
$user=$params['username'];
$pwd=$params['password'];
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);
if (!$conn)
{
error_log("mysql connected error!");
}
mysql_select_db($mysql_database,$conn);
$sql="update users set password='$pwd' where username='$user'";
if (!mysql_query($sql,$conn))
{
error_log('Error: ' . mysql_error());
}
mysql_close($conn);
}
这篇关于为Postfix增加验证模块的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!