以下的文章主要介绍的是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>
则在/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>
其中到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>
例如:你想在增加用户以后干些事情,就以增加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>
针对第二个问题,实际上上面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>.
编译之后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>
/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>
注:原来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>
而且,如果要方便扩展的话,可以将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>
而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>
以上的相关内容就是对qmailadmin+vpopmail+MySQL filter的配置的介绍,望你能有所收获。