Commit f4d3e78d f4d3e78db91212292c8609a4eb18f6402520978a by Alain Magloire

* 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.
1 parent 7ba96ca1
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}.
......
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
......
noinst_LIBRARIES = libmailMysql.a
libmailMysql_a_SOURCES = MySql.c
noinst_HEADERS = MySql.h
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <config.h>
#ifdef HAVE_MYSQL
#ifdef HAVE_SHADOW_H
#include <shadow.h>
#endif /* HAVE_SHADOW_H */
#include <mysql/mysql.h>
#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 */
#include <config.h>
#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 */
......@@ -9,3 +9,4 @@ of errors.
Frank Belew <frb@wiw.org>
Vesselin Atanasov <vesselin@bgnet.bg>
Sergey Poznyakoff <gray@Mirddin.farlep.net>
Jim Hull <imaginos@imaginos.net>
......
......@@ -44,3 +44,6 @@
/* Define the default loggin facility. */
#undef LOG_FACILITY
/* Define HAVE_MYSQL when using mysql */
#undef HAVE_MYSQL
......
......@@ -129,6 +129,15 @@ if test x"$ac_cv_func_argp_parse" != xyes; then
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 @@ AC_OUTPUT(Makefile mailutils.spec include/Makefile include/mailutils/Makefile
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)
......
......@@ -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 @@ imap4d_login (struct imap4d_command *command, char *arg)
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 @@ imap4d_login (struct imap4d_command *command, char *arg)
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;
......
......@@ -30,6 +30,10 @@
# include <paths.h>
#endif
#ifdef HAVE_MYSQL
#include "../MySql/MySql.h"
#endif
#include <mailutils/mailbox.h>
#include <mailutils/error.h>
......@@ -79,6 +83,12 @@ get_homedir (const char *user)
if (user)
{
pw = getpwnam (user);
#ifdef HAVE_MYSQL
if (!pw)
pw = getMpwnam(user);
#endif /* HAVE_MYSQL */
if (pw)
homedir = pw->pw_dir;
}
......
......@@ -31,6 +31,10 @@
#include <mailutils/mutil.h>
#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 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
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)
{
......
......@@ -32,6 +32,10 @@
#include <mailutils/mutil.h>
#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 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
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)
{
......
......@@ -17,6 +17,10 @@
#include "pop3d.h"
#ifdef HAVE_MYSQL
#include "../MySql/MySql.h"
#endif
/*
APOP name digest
......@@ -203,6 +207,10 @@ pop3d_apop (const char *arg)
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;
......
......@@ -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 @@ pop3d_user (const char *arg)
#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 @@ pop3d_user (const char *arg)
#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 */
......