Actual configuration of MySQLfilter

Source: Internet
Author: User
Tags qmail
The following articles mainly introduce the actual configuration of qmailadmin + vpopmail + MySQLfilter. If you are interested in the actual operations, you can click and view the following articles. I hope it will help you with the actual configuration of MySQLfilter. The method acting on qmail-local (that is, MDA. There are several questions to ask.

The following articles mainly introduce the actual configuration of qmailadmin + vpopmail + MySQL filter. If you are interested in the actual operations, you can click and view the following articles. I hope it will help you with the actual configuration of MySQL filter. The method acting on qmail-local (that is, MDA. There are several questions to ask.

The following articles mainly introduce the actual configuration of qmailadmin + vpopmail + MySQL filter. If you are interested in the actual operations, you can click and view the following articles. I hope it will help you with the actual configuration of MySQL filter.

The method acting on qmail-local (that is, MDA.

There are several problems to solve.

1. How to automatically initialize your initial MySQL filter file when creating a user.

2. How does the filter defined by webmail work.

3. There are also some problems encountered in the process of solving these problems.

For the first problem, I studied qmailadmin and found out after reading the code,

Qmailadmin supports plug-in configuration files,

Run the script defined in the plug-in configuration file. The script is for each domain, that is, placed under the directory of the domain.

No introduction on the Internet. It is estimated that it is inter7 unleased.

The Directory of the domain is located through/var/qmail/users/assign. For example, the content of assign is as follows:

 
 
  1. +foo.com-:foo.com:515:511:/home/vpopmail/domains/foo.com:-::

A configuration file. qmailadmin-hooks is defined in/home/vpopmail/domains/foo.com. Note:

The configuration file format is as follows:

 
 
  1. #....
  2. op: cmd

To the qmailadmin-1.06, op supports the following operations:

 
 
  1. "adduser",
  2. "deluser",
  3. "moduser",
  4. "addmaillist",
  5. "delmaillist",
  6. "modmaillist",
  7. "listadduser",
  8. "listdeluser"

For example, if you want to do something after adding a user, add MySQL filter as an example. qmailadmin-hooks

The configuration can be as follows:

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

The inituser. sh script is as follows:

 
 
  1. #!/bin/bash
  2. Domain=$1
  3. User=$3
  4. Passwd=$2
  5. DomainPath=/home/vpopmail/domains/$Domain
  6. umask 0177
  7. exec 1> /tmp/adduser.log
  8. exec 2> /tmp/adduser.log
  9. echo $DomainPath
  10. cat>$DomainPath/.qmail-$User <|maildrop $DomainPath/$User/.mailfilter
  11. EOF
  12. cat>$DomainPath/$User/.mailfilter
  13. EOF
  14. cat>$DomainPath/$User/.userfilter <#MFMAILDROP=2
  15. #
  16. # DO NOT EDIT THIS FILE. This is an automatically generated filter.
  17. FROM='$User@$Domain'
  18. import SENDER
  19. if ($SENDER ne "")
  20. {
  21. FROM=$SENDER
  22. }
  23. to "$DomainPath/$User/Maildir/."
  24. EOF
  25. cat>$DomainPath/$User/Maildir/maildirfilterconfig
  26. MAILDIR=$DomainPath/$User/Maildir
  27. EOF

For the second problem, inituser. sh has provided a solution, that is, sqwebmail

Maildirfilterconfig is used to find the MySQL filter file. The definition is ../. userfilter, which is included in. mailfiter,

Point. mailfilter is the rule file called by maildrop.

There are several points to explain,

1. Comments in the first few lines of userfilter are valid. They are the sqwebmail mark and cannot be removed. Otherwise, sqwebmail reports an error.

2. Why does MAILDIRFILTER point to. mailfiter instead of. userfilter. You can add it to. mailfilter.

Other MySQL filters rule, which do not need to be edited by the user.

3. The script in qmailadmin-hook is executed by the sub-process qmailadmin fork. qmailadmin is run by an http user.

So there will be errors when creating these files. Therefore, we have changed the source code in the qmailadmin */user. c directory of the source code package.

Before the fork function of call_hooks, it is as follows:

 
 
  1. + setuid(0);
  2. + setgid(VPOPMAILGID);
  3. + setuid(VPOPMAILUID);
  4. pid = fork();
.

After compiling qmailadmin, replace the files in the cgi directory. Note that the owner is the root and setuid bits.

4. Why isn't su used for execution in inituser. sh, so you don't need to change the code? First, apache (the most popular WEB server platform on Unix) Redirects stdin, while su checks

Stdin is not tty. If not, it will not be executed. Second, the fork sub-process is exec to execute the commands specified in the MySQL filter configuration,

Exec does not copy euid and egid, so if you do not need su, you need to compile a suid program by yourself. This is troublesome.

. Qmailadmin-hooks is as follows:

 
 
  1. adduser: /home/vpopmail/bin/inituser.sh
  2. deluser: /home/vpopmail/bin/deluser.sh

/Var/vpopmail/bin/deluser. sh:

 
 
  1. #!/bin/bash
  2. Domain=$1
  3. User=$3
  4. Passwd=$2
  5. DomainPath=/home/vpopmail/domains/$Domain
  6. rm -f $DomainPath/.qmail-$User

Note: The original qmailadmin has a bug.

In this line of the qmailadmin */user. c function call_hooks in the source package

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

The problem is obvious here. The second parameter of execl is arg0, which does not actually work. While Gecos is the real user

User name, which is a value only when it is created. If it is left blank, It is Newu. Therefore, I thought the user name is $3.

However, when moduser and deluser are used, the Operation user name is not in Newu, but in ActionUser.

Therefore, the deluser and moduser scripts defined in the hook cannot obtain the user name.

So you need to change this line

 
 
  1. if (Newu %26amp;%26amp; *Newu) {
  2. error = execl(cmd, cmd, Newu, Domain, Password1, Gecos, NULL);
  3. } else {
  4. error = execl(cmd, cmd, ActionUser, Domain, Password1, Gecos, NULL);
  5. }

In addition, if you want to facilitate expansion, you can also put op in the execl parameter. In this way,

You can use a script. The operation is based on the op type. It's not like dividing it into many scripts like me.

Therefore, after user. c is finished, the following is near the fork of the call_hooks function:

 
 
  1. setuid(0);
  2. setgid(VPOPMAILGID);
  3. setuid(VPOPMAILUID);
  4. pid = fork();
  5. #ifdef DEBUG
  6. fprintf(actout,"Where the parameters are: %s, "%s", %s, %s, %s, %s, NULL); ",
  7. cmd, hooks[hook_type], Newu, Domain, Password1, Gecos);
  8. #endif
  9. if (pid == 0) {
  10. // error = execl(cmd, Newu, Domain, Password1, Gecos, NULL);
  11. if (Newu %26amp;%26amp; *Newu) {
  12. error = execl(cmd, cmd, Newu, Domain, Password1, Gecos, NULL);
  13. } else {
  14. error = execl(cmd, cmd, ActionUser, Domain, Password1, Gecos, NULL);
  15. }

Inituser. sh and deluser also need to change the parameter location. I only paste the modified header lines as follows:

 
 
  1. #!/bin/sh
  2. User=$1
  3. Domain=$2
  4. Passwd=$3
  5. RealName=$4

The above content is an introduction to the configuration of qmailadmin + vpopmail + MySQL filter. I hope you will find some gains.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.