Commit ceefa4fb ceefa4fbe8a9e53ceffe754142b05aba1bbc2e01 by Alain Magloire

Missing doc/Readme.mysql and examples/mail.MysqlMailer.c

1 parent f4d3e78d
Author: Jim Hull (8-24-2001)
imaginos@imaginos.net
Mysql support for mailutils ....
This addition to mailutils allows you to have complete email support
without actually having the users on the systems. This would allow you to
have complete web based account management for users while still
maintaining system security as the users can not access the box directly.
The setup is designed to work with the same table definitions as ProFtpd
thus granting you the ability to grant complete web/ftp/email based system
all authenticated by a database running in mysql. A current running system
for this exists at http://www.linuxrocket.net/freeweb.cgi.
Setup:
Mysql:
create database mail;
grant all privileges on mail.* to user@localhost identified by
'foobar';
create table users (username VARCHAR(20) UNIQUE NOT NULL,
uid INT(5) NOT NULL DEFAULT 99,
gid INT(5) NOT NULL DEFAULT 99,
password VARCHAR(15) NOT NULL,
homedir VARCHAR(128) NOT NULL,
shell VARCHAR(64) NOT NULL,
comment TEXT);
When you are done, it should look like ....
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| username | varchar(20) | | PRI | | |
| uid | int(5) | | | 99 | |
| gid | int(5) | | | 99 | |
| password | varchar(15) | | | | |
| homedir | varchar(128) | | | | |
| shell | varchar(64) | | | | |
| comment | text | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
System Setup:
After modifying MySql/MySql.h with your appropriate defines, compile and
install.
Add a user with no possibility of a pass, with its own gid, shell should
be /bin/false and dir should be /dev/null. Something like ...
monly:x:3002:805:Mail Only:/dev/null:/bin/false
monly:x:805:
When you enter new users into your table, you want to be sure they all
have the same uid/gid in the table as that one user on the system. If you
use the mailer thats in examples/mail.MysqlMailer.c then you will be all
ready to go. It explains in the source for its setup and installation.
an example entry would be ...
+----------+------+------+---------------+-------------------------+------------+----------+
| username | uid | gid | password | homedir | shell | comment |
+----------+------+------+---------------+-------------------------+------------+----------+
| foobar | 3002 | 805 | JahUAjwjhAJha | /home/foobar | /bin/false | F. Bar |
+----------+------+------+---------------+-------------------------+------------+----------+
1) make sure /var/spool/foobar is uid '3002', gid 'mail' and 0660
2) make sure /home/foobar is uid '3002', gid '805' so when you set up
proftpd it works in unison
#include <stdlib.h>
#include <stdio.h>
#include <mysql/mysql.h>
#include <unistd.h>
#include <string.h>
#include <sysexits.h>
#include <sys/types.h>
#include <sys/stat.h>
/**********************************************************************
** mailer to go with gnu-pop3d patch, works with sendmail
** add the following in sendmail.cf right after virtusertable ruleset
** R$* < $* @ yourdomain . net . > $#MysqlMailer $: $1
**
** Then after local mailer, add the following
** MMysqlMailer, P=/usr/local/bin/mail.MysqlMailer, F=lsDFMoqeu9, S=10/30, R=20/40,
** A=mail.MysqlMailer $u
**
** compile with gcc -o mail.MysqlMailer mail.MysqlMailer.c -lmysqlclient
**
** chown it so it is owned by same owner of your psuedo mails (mine is monly)
** and same group as owner sendmail runs as
** then chmod 4711. If you have local users on your box (shell accounts) you may want
** to declare AGENT as read-only in /etc/profile (declare -r AGENT).
**
** Author: Jim Hull (08-24-2001)
** imaginos@imaginos.net
**********************************************************************/
#define USERNAME "username" /* username field */
#define TABLE "table" /* table name */
#define Muser "user" /* Mysql username */
#define Mpass "password" /* Mysql password */
#define Mdb "db" /* Mysql Database Name */
int main(int argc, char **argv)
{
FILE *f;
char QueryStr[1024], *user, path[128], output[1024], *agent;
MYSQL *m;
MYSQL_RES *res;
MYSQL_ROW row;
int i;
if (argc != 2)
exit(EX_NOUSER);
agent = getenv("AGENT");
if (!agent)
exit(EX_NOUSER);
if (strcmp(getenv("AGENT"), "sendmail") != 0)
exit(EX_NOUSER);
user = strdup(argv[1]);
memset((char *)QueryStr, '\0', 1024);
memset((char *)path, '\0', 128);
m = mysql_init(0);
if (!m)
exit(EX_NOUSER);
if (!mysql_real_connect(m, NULL, Muser, Mpass, Mdb, 0, NULL, 0))
exit(EX_NOUSER);
sprintf(QueryStr, "select %s from %s where %s = '%s' limit 1", USERNAME, TABLE, USERNAME, user);
if (mysql_query(m, QueryStr) != 0)
exit(EX_NOUSER);
if ((res = mysql_store_result(m)) == NULL)
exit(EX_NOUSER);
if ((row = mysql_fetch_row(res)) == NULL)
exit(EX_NOUSER);
sprintf(path, "/var/spool/mail/%s", row[0]);
f = fopen(path, "a");
if (!f)
exit(EX_NOUSER);
while (!feof(stdin))
{
memset((char *)output, '\0', 1024);
fgets(output, 1024, stdin);
fprintf(f, "%s", output);
}
chmod(path, S_IWUSR|S_IRUSR|S_IRGRP|S_IWGRP);
fclose(f);
exit(0);
}