Home Database Mysql Tutorial MySQL filter的实际配置

MySQL filter的实际配置

Jun 07, 2016 pm 04:11 PM
filter mysql main introduce actual article Configuration

以下的文章主要介绍的是qmailadmin+vpopmail+MySQL filter的实际配置,如果你对其相关的实际操作有兴趣的话,你就可以对以下的文章点击观看了。希望会给你带来一些帮助在MySQL filter的实际配置方面。 作用于qmail-local(即MDA)的方法。 这里有几个问题,需

以下的文章主要介绍的是qmailadmin+vpopmail+MySQL filter的实际配置,如果你对其相关的实际操作有兴趣的话,你就可以对以下的文章点击观看了。希望会给你带来一些帮助在MySQL filter的实际配置方面。

作用于qmail-local(即MDA)的方法。

这里有几个问题,需要解决。

1.如何在建用户的时候自动的初始化用户的初始MySQL filter文件.

2.webmail定义的filter如何起作用。

3.还有一些是解决这些问题的过程中遇到的问题。

针对第一个问题,研究了一下qmailadmin,看了代码之后才发现,

qmailadmin支持插件似的配置文件,在操作用户后,

运行在插件配置文件中定义的脚本。脚本是针对每个域的,即放在域的目录下面。

呵呵,网上都没有介绍哦,估计是inter7 unleased.

域的目录通过/var/qmail/users/assign来定位。例如,assign的内容如下:

<ol class="dp-xml"><li class="alt"><span><span>+foo.com-:foo.com:515:511:/home/vpopmail/domains/foo.com:-::  </span></span></li></ol>
Copy after login

则在/home/vpopmail/domains/foo.com下定义一个配置文件.qmailadmin-hooks。注意属

主和属性,这个配置文件格式如下:

<ol class="dp-xml">
<li class="alt"><span><span>#....   </span></span></li>
<li><span>op: cmd </span></li>
</ol>
Copy after login

其中到qmailadmin-1.06,op支持以下一些操作

<ol class="dp-xml">
<li class="alt"><span><span>"adduser",   </span></span></li>
<li><span>"deluser",   </span></li>
<li class="alt"><span>"moduser",   </span></li>
<li><span>"addmaillist",   </span></li>
<li class="alt"><span>"delmaillist",   </span></li>
<li><span>"modmaillist",   </span></li>
<li class="alt"><span>"listadduser",   </span></li>
<li><span>"listdeluser"  </span></li>
</ol>
Copy after login

例如:你想在增加用户以后干些事情,就以增加MySQL filter为例,.qmailadmin-hooks

就可以这么配:

adduser: /home/vpopmail/bin/inituser.sh

inituser.sh脚本如下:

<ol class="dp-xml">
<li class="alt"><span><span>#!/bin/bash   </span></span></li>
<li>
<span class="attribute">Domain</span><span>=$1   </span>
</li>
<li class="alt">
<span class="attribute">User</span><span>=$3   </span>
</li>
<li>
<span class="attribute">Passwd</span><span>=$2   </span>
</li>
<li class="alt">
<span class="attribute">DomainPath</span><span>=/home/vpopmail/domains/$Domain   </span>
</li>
<li><span>umask 0177   </span></li>
<li class="alt">
<span>exec 1</span><span class="tag">></span><span> /tmp/adduser.log   </span>
</li>
<li>
<span>exec 2</span><span class="tag">></span><span> /tmp/adduser.log   </span>
</li>
<li class="alt"><span>echo $DomainPath   </span></li>
<li>
<span>cat</span><span class="tag">></span><span>$DomainPath/.qmail-$User </span><span class="tag"><span>|maildrop $DomainPath/$User/.mailfilter   </span></span>
</li>
<li class="alt"><span>EOF   </span></li>
<li>
<span>cat</span><span class="tag">></span><span>$DomainPath/$User/.mailfilter </span><span class="tag"><span class="tag-name">include</span><span> $User/.userfilter   </span></span>
</li>
<li class="alt"><span>EOF   </span></li>
<li>
<span>cat</span><span class="tag">></span><span>$DomainPath/$User/.userfilter </span><span class="tag"><span>#</span><span class="attribute">MFMAILDROP</span><span>=</span><span class="attribute-value">2</span><span>   </span></span>
</li>
<li class="alt"><span>#   </span></li>
<li><span># DO NOT EDIT THIS FILE. This is an automatically generated filter.   </span></li>
<li class="alt">
<span class="attribute">FROM</span><span>=</span><span class="attribute-value">'$User@$Domain'</span><span>   </span>
</li>
<li><span>import SENDER   </span></li>
<li class="alt"><span>if ($SENDER ne "")   </span></li>
<li><span>{   </span></li>
<li class="alt">
<span class="attribute">FROM</span><span>=$SENDER   </span>
</li>
<li><span>}   </span></li>
<li class="alt"><span>to "$DomainPath/$User/Maildir/."   </span></li>
<li><span>EOF   </span></li>
<li class="alt">
<span>cat</span><span class="tag">></span><span>$DomainPath/$User/Maildir/maildirfilterconfig </span><span class="tag"><span class="attribute">MAILDIRFILTER</span><span class="tag-name">MAILDIRFILTER</span><span>=../.userfilter   </span></span>
</li>
<li>
<span class="attribute">MAILDIR</span><span>=$DomainPath/$User/Maildir   </span>
</li>
<li class="alt"><span>EOF   </span></li>
</ol>
Copy after login

针对第二个问题,实际上上面inituser.sh已经提供了解决方法,也就是sqwebmail通过

maildirfilterconfig来查找MySQL filter文件,这里定义的是../.userfilter,它有包含在.mailfiter中,

而点.mailfilter则是maildrop调用的规则文件。

这里有几个地方需要解释,

1..userfilter中的前几行comment是起作用的,是sqwebmail的标记,不能去掉,否则sqwebmail会报错

2.MAILDIRFILTER为什么不指向.mailfiter,而是.userfilter,一句话方便扩充。可以在.mailfilter中加入

其它的MySQL filter rule, 而这些rule并不需要用户编辑。

3..qmailadmin-hook中的脚本是qmailadmin fork出的子进程执行的,qmailadmin由于是以http的用户运行

所以建立这些文件的时候会有错误。因此,我们改了一点源代码,位置在源码包的qmailadmin*/user.c的

函数call_hooks的fork之前, 如下:

<ol class="dp-xml">
<li class="alt"><span><span>+ setuid(0);   </span></span></li>
<li><span>+ setgid(VPOPMAILGID);   </span></li>
<li class="alt"><span>+ setuid(VPOPMAILUID);   </span></li>
<li>
<span class="attribute">pid</span><span> = </span><span class="attribute-value">fork</span><span>();  </span>
</li>
</ol>.
Copy after login

编译之后qmailadmin后,并替换cgi目录下的文件,注意属主是root和setuid位.

4.为什么不在inituser.sh中用su来执行,这样就不用改代码了?首先,apache(Unix平台最流行的WEB服务器平台)重定向了stdin,而su是检查

stdin是不是tty,如果不是,就不会执行。其次,fork出来的子进程是exec的方式执行MySQL filter的配置中指定的命令,

而exec是不复制euid和egid的,所以如果不用su,就需要用自己编一个suid的程序。这又麻烦了.

.qmailadmin-hooks如下:

<ol class="dp-xml">
<li class="alt"><span><span>adduser: /home/vpopmail/bin/inituser.sh   </span></span></li>
<li><span>deluser: /home/vpopmail/bin/deluser.sh  </span></li>
</ol>
Copy after login

/var/vpopmail/bin/deluser.sh如下

<ol class="dp-xml">
<li class="alt"><span><span>#!/bin/bash   </span></span></li>
<li>
<span class="attribute">Domain</span><span>=$1   </span>
</li>
<li class="alt">
<span class="attribute">User</span><span>=$3   </span>
</li>
<li>
<span class="attribute">Passwd</span><span>=$2   </span>
</li>
<li class="alt">
<span class="attribute">DomainPath</span><span>=/home/vpopmail/domains/$Domain   </span>
</li>
<li><span>rm -f $DomainPath/.qmail-$User  </span></li>
</ol>
Copy after login

注:原来qmailadmin有bug.

在源码包的qmailadmin*/user.c的函数call_hooks的这行

error = execl(cmd, Newu, Domain, Password1, Gecos, NULL);

这里明显有问题,execl的第二个参数是arg0,实际上不起作用。而Gecos是用户的真实

用户名,只有在新建的时候才有值,不填就是Newu,所以我以为用户名是$3.

但是moduser和deluser的时候,操作的用户名都不在Newu里面,而是在ActionUser里面。

所以hook中定义的deluser和moduser脚本取不到用户名.

所以需要将这行改为

<ol class="dp-xml">
<li class="alt"><span><span>if (Newu %26amp;%26amp; *Newu) {   </span></span></li>
<li>
<span class="attribute">error</span><span> = </span><span class="attribute-value">execl</span><span>(cmd, cmd, Newu, Domain, Password1, Gecos, NULL);   </span>
</li>
<li class="alt"><span>} else {   </span></li>
<li>
<span class="attribute">error</span><span> = </span><span class="attribute-value">execl</span><span>(cmd, cmd, ActionUser, Domain, Password1, Gecos, NULL);   </span>
</li>
<li class="alt"><span>}  </span></li>
</ol>
Copy after login

而且,如果要方便扩展的话,可以将op也放在execl的参数中,这样,hook中定义的

脚本就可以用一个。根据op类型来操作。就不像我这样分成好多脚本了。

所以user.c最终该过后,如下,call_hooks函数的fork附近:

<ol class="dp-xml">
<li class="alt"><span><span>setuid(0);   </span></span></li>
<li><span>setgid(VPOPMAILGID);   </span></li>
<li class="alt"><span>setuid(VPOPMAILUID);   </span></li>
<li>
<span class="attribute">pid</span><span> = </span><span class="attribute-value">fork</span><span>();   </span>
</li>
<li class="alt"><span>#ifdef DEBUG   </span></li>
<li><span>fprintf(actout,"Where the parameters are: %s, "%s", %s, %s, %s, %s, NULL); ",   </span></li>
<li class="alt"><span>cmd, hooks[hook_type], Newu, Domain, Password1, Gecos);   </span></li>
<li><span>#endif   </span></li>
<li class="alt">
<span>if (</span><span class="attribute">pid</span><span> == 0) {   </span>
</li>
<li>
<span>// </span><span class="attribute">error</span><span> = </span><span class="attribute-value">execl</span><span>(cmd, Newu, Domain, Password1, Gecos, NULL);   </span>
</li>
<li class="alt"><span>if (Newu %26amp;%26amp; *Newu) {   </span></li>
<li>
<span class="attribute">error</span><span> = </span><span class="attribute-value">execl</span><span>(cmd, cmd, Newu, Domain, Password1, Gecos, NULL);   </span>
</li>
<li class="alt"><span>} else {   </span></li>
<li>
<span class="attribute">error</span><span> = </span><span class="attribute-value">execl</span><span>(cmd, cmd, ActionUser, Domain, Password1, Gecos, NULL);   </span>
</li>
<li class="alt"><span>}   </span></li>
</ol>
Copy after login

而inituser.sh和deluser也需要相应的改参数位置,我只贴上修改的头几行如下:

<ol class="dp-xml">
<li class="alt"><span><span>#!/bin/sh   </span></span></li>
<li>
<span class="attribute">User</span><span>=$1   </span>
</li>
<li class="alt">
<span class="attribute">Domain</span><span>=$2   </span>
</li>
<li>
<span class="attribute">Passwd</span><span>=$3   </span>
</li>
<li class="alt">
<span class="attribute">RealName</span><span>=$4   </span>
</li>
<li><span> </span></li>
</ol>
Copy after login

以上的相关内容就是对qmailadmin+vpopmail+MySQL filter的配置的介绍,望你能有所收获。


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's big data structure processing skills PHP's big data structure processing skills May 08, 2024 am 10:24 AM

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the &quot;MySQL Native Password&quot; plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

Detailed introduction of Samsung S24ai functions Detailed introduction of Samsung S24ai functions Jun 24, 2024 am 11:18 AM

2024 is the first year of AI mobile phones. More and more mobile phones integrate multiple AI functions. Empowered by AI smart technology, our mobile phones can be used more efficiently and conveniently. Recently, the Galaxy S24 series released at the beginning of the year has once again improved its generative AI experience. Let’s take a look at the detailed function introduction below. 1. Generative AI deeply empowers Samsung Galaxy S24 series, which is empowered by Galaxy AI and brings many intelligent applications. These functions are deeply integrated with Samsung One UI6.1, allowing users to have a convenient intelligent experience at any time, significantly improving the performance of mobile phones. Efficiency and convenience of use. The instant search function pioneered by the Galaxy S24 series is one of the highlights. Users only need to press and hold

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

See all articles