Friday, April 22, 2011

Database Connections made by IndiMail

IndiMail uses MySQL for storing information of virtual domain users. The table 'indimail' stores important user information like password, access permissions, quota and the mailbox path. Most of user related queries have to lookup the 'indimail' table in MySQL.
Rather than making individual connections to MySQL for extracting information from the 'indimail' table, IndiMail programs use the service of the inlookup(8) server. Programs use an API function inquery() to request service. InLookup is a connection pooling server to serve requests for inquery() function. It is implemented over two fifos. One fixed fifo for reading the query and reading the path of a randomly generated fifo. The randomly generated fifo is used for writing the result of the query back. inlookup(8) creates a read FIFO determined by the environment variable INFIFO. If INFIFO is not defined, the default FIFO used is /var/indimail/inquery/infifo. inlookup(8) then goes into an infinite loop reading this FIFO. If INFIFO is not an absolute path, inlookup(8) uses environment variable FIFODIR to look for fifo named by INFIFO variable. Inlookup(8) can be configured by setting environment variables in /service/inlookup.info/variables
  • inlookup helps in optimizing connection to MySQL(1), by keeping the connections persistent.
  • It also maintains the query result in a double link list.
  • It uses binary tree algorithm to search the cache before actually sending the query to the database.
  • IndiMail clients send requests for MySQL(1) queries to inlookup through the function inquery() using a fifo.
  • The inquery() API uses the InLookup service only if the environment variable QUERY_CACHE is set. If this environment variable is not set, the inquery() function makes a direct connecton to MySQL.
  • Clients which are currently using inquery are qmail-smtpd(1), proxyimap(8), proxypop3(8), vchkpass(8) and authindi(8).
  • inlookup(8) service is one of the reasons why IndiMail is able to serve million+ users using commodity hardware.
The program inquerytest simulates all the queries which inlookup supports and can be used as a test/diagnostic tool for submitting queries to inlookup. e.g
% sudo inquerytest -q 3 -i "" user@example.com



Friday, April 15, 2011

Plugin for qmail-smtpd

IndiMail now has a plugin functionality for qmail-smtpd. You can write your own plugin to carry out tasks during the MAIL, RCPT or the DATA phase of SMTP.  See the man page for plugin_init(3) for details.

NAME
plugin_init() - Template for Dynamic SMTP Plugins

SYNTAX
#include smtp_plugin.h

char *from_plug(char *rip, char *from, char **mesg);

char *rcpt_plug(char *rip, char *from, char *rcpt, char **mesg);

char *data_plug(char *local, char *rip, char *rhost, char *rinfo, char **mesg);

PLUGIN *plugin_init();

typedef struct
{
int (*mail_func) (char *, char *, char **);
int (*rcpt_func) (char *, char *, char *, char **);
int (*data_func) (char *, char *, char *, char *, char **);
} PLUGIN;

DESCRIPTION
PLUGIN structure has three components: mail_func is a pointer to function to be exe‐
cuted in the SMTP MAIL session. rcpt_func is a pointer to function to be executed in
the SMTP RCPT session. data_func is a pointer to function to be executed in the SMTP
DATA session.

To write a SMTP plugin you have to write the plugin_init() function. Depending on
which phase of SMTP (MAIL, RCPT, DATA) you want to call your function, you have to
write the from_plug, rcpt_plug, data_plug functions.

The plugin_init() function can be written as below

PLUGIN *
plugin_init()
{
static PLUGIN plug;
PLUGIN *ptr;

ptr = &plug;
ptr->mail_func = from_plug;
ptr->rcpt_func = rcpt_plug;
ptr->data_func = data_plug;
return &plug;
}

To compile the plugin you can use gcc(1).

gcc -shared -rdynamic -nostartfiles -fPIC -s -O4 -o smtpd-plugin.so smtp_plugin.o

RETURN VALUE
The functions from_plug, rcpt_plug, data_plug must return 0 on success. These func‐
tions should return 1 to terminate the sesson with a message. You can set your own
message by assigning mesg variable. If you have the below function in smtpd-plugin.so

int
rcpt_plug(char *remoteip, char *from, char *rcpt, char **mesg)
{
if (!strstr(rcpt, "@yahoo.com"))
{
*mesg = "530 We are serious and don't Yahoo (#5.7.1)
return (1);
}
return (0);
}

SEE ALSO
qmail-smtpd(8), dlopen(3), gcc(1)

Friday, April 1, 2011

The AdminClient Protocol

IndiMail provides close to around 300 different programs as part of a flexible Enterprise Messaging Platform. You can carry administer the entire platform with around 45 of these programs. A program called indisrvr(8) provides a way for users to secure execute these commands from any remote location. To execute these programs, you need to have an admin account on the IndiMail server. These accounts can be created by the mgmtpass(8) program. Once you have an admin account on the IndiMail server, you can further restrict users to certain programs using the vpriv(8) program. vpriv can further modify privileges by allowing only certain options within a allowed program.

To execute these programs on the IndiMail server, you need to connect to port 4000 and use the adminclient protocol. The adminclient protocol is described below by showing a conversation between a client and the server 'indisrvr'


s - denotes server
c - denotes client

        s: "Login: "
        c: "userid\n"
        s: "Password: "
        c: "password\n"
        s: "OK\n"
        c: "index command arg1 arg2 ...\n"
        s:
        c: "\n"
        s: "RETURNSTATUS[return value of command]\n"

To execute 'vuserinfo' you will need to do the following.

        % telnet 0 4000
        Trying 0.0.0.0...
        Connected to 0.
        Escape character is '^]'.
        Login: admin
        Password: benhur20
        OK
        7 vuserinfo -n manvendra@indimail.org
        name          : manvendra@indimail.org
        
        RETURNSTATUS0

Index value of '7' was used for vuserinfo. A privileged user 'admin' with password 'benhur20' was used to execute vuserinfo. Each command has an index. The values are given as below.

Index Commands
----- --------
00    vadduser
01    vpasswd
02    vdeluser
03    vsetuserquota
04    vbulletin
05    vmoduser
06    valias
07    vuserinfo
08    vipmap
09    vacation
10    vmoveuser
11    vrenameuser
12    crc
13    vcfilter
14    indiversion
15    vsmtp
16    dbinfo
17    vhostid
18    mgmtpass
19    inquerytest
20    printdir
21    shit
22    vaddaliasdomain
23    vadddomain
24    vcalias
25    vcaliasrev.sh
26    vconvert
27    vdeldomain
28    vrenamedomain
29    vdominfo
30    vfstab
31    vgroup
32    vatrn
33    vpriv
34    vlimit
35    hostcntrl
36    execmysql
37    updatefile
38    vreorg
39    vdeloldusers
40    ipchange
41    svctool
42    clearopensmtp
43    hostsync
44    inquerytest
45    vmoddomain

If you have a user provisioning interface written in your favourite language, you can connect to the port 4000 and execute the above programs. IndiMail also provides you a command line program 'adminclient' which can execute any of the above programs. Read the man page for adminclient for further details.

IndiMail Queue Mechanism

Indimail has the ability of configuring multiple local and remote queues. A queue is a location on your hard disk where email are deposited ...