diff -ruwN mailutils/ChangeLog mailutils-jim/ChangeLog --- mailutils/ChangeLog Fri Aug 24 17:52:37 2001 +++ mailutils-jim/ChangeLog Fri Aug 24 21:28:42 2001 @@ -1,3 +1,25 @@ +2001-08-24 Jim Hull + + * Makefile.am: + * acconfig.h: Added support for new MySql addition to mailutils + * configure.in: + + * MySql/Makefile.am: + * MySql/MySql.c: Mini lib to link to when mysql support + * MySql/MySql.h: enabled (with --enable-mysql) + + * doc/Readme.mysql: Readme file for setup. + + * imap4d/login.c: + * mailbox/mbx_default.c: The Patch pretty much works the same + * mailbox/mutil.c: all around. if getpwnam() returns null + * mailbox2/mutil.c: then your db is checked for the user, + * pop3d/apop.c: and the struct is filled if found, + * pop3d/user.c: returns null if not. If shadow support + is used, then the same is done with getspnam(). + + * examples/mail.MysqlMailer.c: Simple sendmail backend support. + 2001-08-24 Alain Magloire * sieve/Makefile.am: To EXTRA_DIST add md5-rsa.{c,h}. diff -ruwN mailutils/Makefile.am mailutils-jim/Makefile.am --- mailutils/Makefile.am Fri Jul 20 17:11:00 2001 +++ mailutils-jim/Makefile.am Fri Aug 24 21:35:06 2001 @@ -1,7 +1,7 @@ AUTOMAKE_OPTIONS = gnu 1.4 ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = include doc m4 lib argp mailbox frm from pop3d imap4d mail sieve \ +SUBDIRS = include doc m4 lib MySql argp mailbox frm from pop3d imap4d mail sieve \ scripts libmu_scm guimb messages EXTRA_DIST = mailutils.spec mailutils.spec.in README-alpha COPYING.FDL diff -ruwN mailutils/MySql/Makefile.am mailutils-jim/MySql/Makefile.am --- mailutils/MySql/Makefile.am Wed Dec 31 16:00:00 1969 +++ mailutils-jim/MySql/Makefile.am Fri Aug 24 21:35:06 2001 @@ -0,0 +1,6 @@ +noinst_LIBRARIES = libmailMysql.a + +libmailMysql_a_SOURCES = MySql.c + +noinst_HEADERS = MySql.h + diff -ruwN mailutils/MySql/MySql.c mailutils-jim/MySql/MySql.c --- mailutils/MySql/MySql.c Wed Dec 31 16:00:00 1969 +++ mailutils-jim/MySql/MySql.c Fri Aug 24 21:35:06 2001 @@ -0,0 +1,119 @@ +#include +#include +#include + +#include + +#ifdef HAVE_MYSQL + +#ifdef HAVE_SHADOW_H +#include +#endif /* HAVE_SHADOW_H */ + +#include +#include "MySql.h" + +struct passwd *getMpwnam (const char *username) +{ + char QueryStr[1024]; + MYSQL *m; + MYSQL_RES *res; + MYSQL_ROW row; + struct passwd *tpw; + + m = mysql_init(0); + + if (!m) + return(NULL); + + if (!mysql_real_connect(m, NULL, MUSER, MPASS, MDB, 0, NULL, 0)) + return(NULL); + + memset((char *)QueryStr, '\0', 1024); + + sprintf(QueryStr, "select %s,%s,%s,%s,%s from %s where %s = '%s'", Mpassword, Muid, Mgid, Mhomedir, Mshell, Mtable, Musername, username); + + if (mysql_query(m, QueryStr) != 0) + return(NULL); + + if ((res = mysql_store_result(m)) == NULL) + return(NULL); + + if ((row = mysql_fetch_row(res)) == NULL) + return(NULL); + + tpw = (struct passwd *)malloc(sizeof(struct passwd)); + + tpw->pw_name = malloc(strlen(username)+1); + strcpy(tpw->pw_name, username); + + tpw->pw_passwd = malloc(strlen(row[0])+1); + strcpy(tpw->pw_passwd, row[0]); + + tpw->pw_uid = atoi(row[1]); + tpw->pw_gid = atoi(row[2]); + + tpw->pw_gecos = malloc(strlen("Mysql User")+1); + strcpy(tpw->pw_gecos, "Mysql User"); + + tpw->pw_dir = malloc(strlen(row[3])+1); + strcpy(tpw->pw_dir, row[3]); + + tpw->pw_shell = malloc(strlen(row[4])+1); + strcpy(tpw->pw_shell, row[4]); + + mysql_free_result(res); + return(tpw); +} + + +#ifdef HAVE_SHADOW_H + +struct spwd *getMspnam (const char *username) +{ + char QueryStr[1024]; + MYSQL *m; + MYSQL_RES *res; + MYSQL_ROW row; + struct spwd *tpw; + + m = mysql_init(0); + + if (!m) + return(NULL); + + if (!mysql_real_connect(m, NULL, MUSER, MPASS, MDB, 0, NULL, 0)) + return(NULL); + + memset((char *)QueryStr, '\0', 1024); + sprintf(QueryStr, "select %s from %s where %s = '%s'", Mpassword, Mtable, Musername, username); + + if (mysql_query(m, QueryStr) != 0) + return(NULL); + + if ((res = mysql_store_result(m)) == NULL) + return(NULL); + + if ((row = mysql_fetch_row(res)) == NULL) + return(NULL); + + tpw = (struct spwd *)malloc(sizeof(struct spwd)); + + tpw->sp_namp = malloc(strlen(username)+1); + strcpy(tpw->sp_namp, username); + + tpw->sp_pwdp = malloc(strlen(row[0])+1); + strcpy(tpw->sp_pwdp, row[0]); + + tpw->sp_lstchg = 11428; + tpw->sp_min = 0; + tpw->sp_max = 99999; + tpw->sp_warn = 7; + + mysql_free_result(res); + return(tpw); +} + +#endif /* HAVE_SHADOW_H */ + +#endif /* HAVE_MYSQL */ diff -ruwN mailutils/MySql/MySql.h mailutils-jim/MySql/MySql.h --- mailutils/MySql/MySql.h Wed Dec 31 16:00:00 1969 +++ mailutils-jim/MySql/MySql.h Fri Aug 24 21:35:06 2001 @@ -0,0 +1,21 @@ +#include + +#ifdef HAVE_MYSQL + +#define MUSER "accounts" /* Username for mysql access */ +#define MPASS "yurpass" /* Password for mysql access */ +#define MDB "accounts" /* Database Name */ +#define Mtable "users" /* Table Name */ +#define Musername "username" /* username field */ +#define Muid "uid" /* uid field */ +#define Mgid "gid" /* gid field */ +#define Mpassword "password" /* password field */ +#define Mhomedir "homedir" /* homedir field */ +#define Mshell "shell" /* shell field */ +#define Mcomment "comment" /* comment field */ + +struct passwd *getMpwnam (const char *username); +struct spwd *getMspnam (const char *username); + + +#endif /* HAVE_MYSQL */ diff -ruwN mailutils/acconfig.h mailutils-jim/acconfig.h --- mailutils/acconfig.h Sun Jun 17 17:06:04 2001 +++ mailutils-jim/acconfig.h Fri Aug 24 21:35:06 2001 @@ -44,3 +44,6 @@ /* Define the default loggin facility. */ #undef LOG_FACILITY + +/* Define HAVE_MYSQL when using mysql */ +#undef HAVE_MYSQL diff -ruwN mailutils/configure.in mailutils-jim/configure.in --- mailutils/configure.in Sat Aug 11 21:31:48 2001 +++ mailutils-jim/configure.in Fri Aug 24 21:35:06 2001 @@ -129,6 +129,15 @@ AC_SUBST(ARGPINCS) fi +dnl check if mysql support was added +AC_ARG_ENABLE(mysql, [ --enable-mysql enable mysql support (default no)], [use_mysql="yes"],,) +if test x"$use_mysql" = x"yes"; then + echo Enabling mysql support, be sure to edit \'MySql/MySql.h\' to change default values + AC_CHECK_HEADER(mysql/mysql.h, + LIBS="$LIBS -lmailMysql -lmysqlclient -L/usr/lib/mysql -L/usr/local/lib/mysql -L../MySql/" + AC_DEFINE(HAVE_MYSQL)) +fi + dnl Use either PAM or CRYPT, not both. if test x"$testpam" = x"yes"; then AC_CHECK_HEADERS(security/pam_appl.h) @@ -220,4 +229,4 @@ m4/Makefile doc/Makefile argp/Makefile lib/Makefile lib/posix/Makefile mailbox/Makefile imap4d/Makefile mailbox/include/Makefile from/Makefile mail/Makefile pop3d/Makefile frm/Makefile sieve/Makefile messages/Makefile - scripts/Makefile libmu_scm/Makefile guimb/Makefile guimb/scm/Makefile) + scripts/Makefile libmu_scm/Makefile guimb/Makefile guimb/scm/Makefile MySql/Makefile) diff -ruwN mailutils/doc/Readme.mysql mailutils-jim/doc/Readme.mysql --- mailutils/doc/Readme.mysql Wed Dec 31 16:00:00 1969 +++ mailutils-jim/doc/Readme.mysql Fri Aug 24 21:33:30 2001 @@ -0,0 +1,71 @@ +Author: Jim Hull (8-24-2001) address@hidden + +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 address@hidden 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 diff -ruwN mailutils/examples/mail.MysqlMailer.c mailutils-jim/examples/mail.MysqlMailer.c --- mailutils/examples/mail.MysqlMailer.c Wed Dec 31 16:00:00 1969 +++ mailutils-jim/examples/mail.MysqlMailer.c Fri Aug 24 21:29:38 2001 @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +/********************************************************************** +** 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) +** address@hidden +**********************************************************************/ + +#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); +} + + + diff -ruwN mailutils/imap4d/login.c mailutils-jim/imap4d/login.c --- mailutils/imap4d/login.c Mon May 28 07:28:39 2001 +++ mailutils-jim/imap4d/login.c Fri Aug 24 21:35:06 2001 @@ -17,6 +17,10 @@ #include "imap4d.h" +#ifdef HAVE_MYSQL +#include "../MySql/MySql.h" +#endif + /* * FIXME: this should support PAM, shadow, and normal password */ @@ -102,7 +106,15 @@ pw = getpwnam (username); if (pw == NULL) +#ifdef HAVE_MYSQL + { + pw = getMpwnam (username); + if (pw == NULL) + return util_finish (command, RESP_NO, "User name or passwd rejected"); + } +#else /* HAVE_MYSQL */ return util_finish (command, RESP_NO, "User name or passwd rejected"); +#endif /* HAVE_MYSQL */ #ifndef USE_LIBPAM if (pw->pw_uid < 1) @@ -113,9 +125,18 @@ struct spwd *spw; spw = getspnam (username); if (spw == NULL || strcmp (spw->sp_pwdp, (char *)crypt (pass, spw->sp_pwdp))) +#ifdef HAVE_MYSQL + { + spw = getMspnam (username); + if (spw == NULL || strcmp (spw->sp_pwdp, (char *)crypt (pass, spw->sp_pwdp))) + return util_finish (command, RESP_NO, "User name or passwd rejected"); + } +#else /* HAVE_MYSQL */ #endif /* HAVE_SHADOW_H */ return util_finish (command, RESP_NO, "User name or passwd rejected"); +#endif /* HAVE_MYSQL */ } + #else /* !USE_LIBPAM */ _user = (char *) username; _pwd = pass; diff -ruwN mailutils/mailbox/mbx_default.c mailutils-jim/mailbox/mbx_default.c --- mailutils/mailbox/mbx_default.c Wed May 23 20:02:06 2001 +++ mailutils-jim/mailbox/mbx_default.c Fri Aug 24 21:35:06 2001 @@ -30,6 +30,10 @@ # include #endif +#ifdef HAVE_MYSQL +#include "../MySql/MySql.h" +#endif + #include #include @@ -79,6 +83,12 @@ if (user) { pw = getpwnam (user); + +#ifdef HAVE_MYSQL + if (!pw) + pw = getMpwnam(user); +#endif /* HAVE_MYSQL */ + if (pw) homedir = pw->pw_dir; } diff -ruwN mailutils/mailbox/mutil.c mailutils-jim/mailbox/mutil.c --- mailutils/mailbox/mutil.c Tue Aug 7 20:47:45 2001 +++ mailutils-jim/mailbox/mutil.c Fri Aug 24 21:35:06 2001 @@ -31,6 +31,10 @@ #include +#ifdef HAVE_MYSQL +#include "../MySql/MySql.h" +#endif + /* convert a sequence of hex characters into an integer */ unsigned long mu_hex2ul(char hex) @@ -294,6 +298,10 @@ memcpy (name, p, s - p); name [s - p] = '\0'; pw = getpwnam (name); +#ifdef HAVE_MYSQL + if (!pw) + pw = getMpwnam(name); +#endif /* HAVE_MYSQL */ free (name); if (pw) { diff -ruwN mailutils/mailbox2/mutil.c mailutils-jim/mailbox2/mutil.c --- mailutils/mailbox2/mutil.c Sun Aug 12 20:53:39 2001 +++ mailutils-jim/mailbox2/mutil.c Fri Aug 24 21:35:06 2001 @@ -32,6 +32,10 @@ #include +#ifdef HAVE_MYSQL +#include "../MySql/MySql.h" +#endif + /* convert a sequence of hex characters into an integer */ unsigned long mu_hex2ul(char hex) @@ -295,6 +299,10 @@ memcpy (name, p, s - p); name [s - p] = '\0'; pw = getpwnam (name); +#ifdef HAVE_MYSQL + if (!pw) + pw = getMpwnam(name); +#endif /* HAVE_MYSQL */ free (name); if (pw) { diff -ruwN mailutils/pop3d/apop.c mailutils-jim/pop3d/apop.c --- mailutils/pop3d/apop.c Sat May 19 19:37:38 2001 +++ mailutils-jim/pop3d/apop.c Fri Aug 24 21:35:06 2001 @@ -17,6 +17,10 @@ #include "pop3d.h" +#ifdef HAVE_MYSQL +#include "../MySql/MySql.h" +#endif + /* APOP name digest @@ -203,6 +207,10 @@ free (user_digest); pw = getpwnam (user); +#ifdef HAVE_MYSQL + if (!pw) + pw = getMpwnam (user); +#endif /* HAVE_MYSQL */ free (user); if (pw == NULL) return ERR_BAD_LOGIN; diff -ruwN mailutils/pop3d/user.c mailutils-jim/pop3d/user.c --- mailutils/pop3d/user.c Wed May 23 09:48:26 2001 +++ mailutils-jim/pop3d/user.c Fri Aug 24 21:35:06 2001 @@ -17,6 +17,10 @@ #include "pop3d.h" +#ifdef HAVE_MYSQL +#include "../MySql/MySql.h" +#endif + #ifdef USE_LIBPAM #define COPY_STRING(s) (s) ? strdup(s) : NULL @@ -134,6 +138,10 @@ #endif pw = getpwnam (arg); +#ifdef HAVE_MYSQL + if (pw == NULL) + pw = getMpwnam (arg); +#endif /* HAVE_MYSQL */ if (pw == NULL) { syslog (LOG_INFO, "User '%s': nonexistent", arg); @@ -148,6 +156,10 @@ #ifdef HAVE_SHADOW_H struct spwd *spw; spw = getspnam ((char *)arg); +#ifdef HAVE_MYSQL + if (spw == NULL) + spw = getMspnam (arg); +#endif /* HAVE_MYSQL */ if (spw == NULL || strcmp (spw->sp_pwdp, (char *)crypt (pass, spw->sp_pwdp))) #endif /* HAVE_SHADOW_H */