diff -ruwN mailutils/Makefile.am mailutils-jim/Makefile.am --- mailutils/Makefile.am Wed Aug 22 20:19:17 2001 +++ mailutils-jim/Makefile.am Wed Aug 22 20:18:33 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 Wed Aug 22 20:18:33 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 Wed Aug 22 20:18:33 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 Wed Aug 22 20:18:33 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 Wed Aug 22 20:19:17 2001 +++ mailutils-jim/acconfig.h Wed Aug 22 20:18:33 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 Wed Aug 22 20:19:17 2001 +++ mailutils-jim/configure.in Wed Aug 22 20:18:33 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/imap4d/login.c mailutils-jim/imap4d/login.c --- mailutils/imap4d/login.c Wed Aug 22 20:19:17 2001 +++ mailutils-jim/imap4d/login.c Wed Aug 22 20:18:33 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 Aug 22 20:19:17 2001 +++ mailutils-jim/mailbox/mbx_default.c Wed Aug 22 20:18:33 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 Wed Aug 22 20:19:17 2001 +++ mailutils-jim/mailbox/mutil.c Wed Aug 22 20:18:33 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 Wed Aug 22 20:19:17 2001 +++ mailutils-jim/mailbox2/mutil.c Wed Aug 22 20:18:33 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 Wed Aug 22 20:19:17 2001 +++ mailutils-jim/pop3d/apop.c Wed Aug 22 20:18:33 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 Aug 22 20:19:17 2001 +++ mailutils-jim/pop3d/user.c Wed Aug 22 20:18:33 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 */