diff -c -N -r sendmail-8.9.3/src/Makefile.m4 sendmail+mysql/src/Makefile.m4
*** sendmail-8.9.3/src/Makefile.m4	Sat Jan 23 18:51:41 1999
--- sendmail+mysql/src/Makefile.m4	Tue Jul 13 14:05:24 1999
***************
*** 32,38 ****
  # see also conf.h for additional compilation flags
  
  # include directories
! INCDIRS=confINCDIRS
  
  # loader options
  LDOPTS=	ifdef(`confLDOPTS', `confLDOPTS')
--- 32,38 ----
  # see also conf.h for additional compilation flags
  
  # include directories
! INCDIRS=confINCDIRS -I/usr/local/include/mysql
  
  # loader options
  LDOPTS=	ifdef(`confLDOPTS', `confLDOPTS')
***************
*** 42,48 ****
  
  # libraries required on your system
  #  delete -l44bsd if you are not running BIND 4.9.x
! LIBS=	ifdef(`confLIBS', `confLIBS')
  
  # location of sendmail binary (usually /usr/sbin or /usr/lib)
  BINDIR=	${DESTDIR}ifdef(`confMBINDIR', `confMBINDIR', `/usr/sbin')
--- 42,48 ----
  
  # libraries required on your system
  #  delete -l44bsd if you are not running BIND 4.9.x
! LIBS=	-lmysqlclient ifdef(`confLIBS', `confLIBS')
  
  # location of sendmail binary (usually /usr/sbin or /usr/lib)
  BINDIR=	${DESTDIR}ifdef(`confMBINDIR', `confMBINDIR', `/usr/sbin')
***************
*** 72,78 ****
  	daemon.o deliver.o domain.o envelope.o err.o headers.o macro.o \
  	main.o map.o mci.o mime.o parseaddr.o queue.o readcf.o recipient.o \
  	safefile.o savemail.o snprintf.o srvrsmtp.o stab.o stats.o \
! 	sysexits.o trace.o udb.o usersmtp.o util.o version.o ${OBJADD}
  
  LINKS=	ifdef(`confLINKS', `confLINKS',
  	`${UBINDIR}/newaliases \
--- 72,79 ----
  	daemon.o deliver.o domain.o envelope.o err.o headers.o macro.o \
  	main.o map.o mci.o mime.o parseaddr.o queue.o readcf.o recipient.o \
  	safefile.o savemail.o snprintf.o srvrsmtp.o stab.o stats.o \
! 	sysexits.o trace.o udb.o usersmtp.o util.o version.o \
! 	get_mysql_pwd.o get_mysql_alias.o mysql_map.o ${OBJADD}
  
  LINKS=	ifdef(`confLINKS', `confLINKS',
  	`${UBINDIR}/newaliases \
diff -c -N -r sendmail-8.9.3/src/get_mysql_pwd.c sendmail+mysql/src/get_mysql_pwd.c
*** sendmail-8.9.3/src/get_mysql_pwd.c	Sat Jul 17 04:30:36 1999
--- sendmail+mysql/src/get_mysql_pwd.c	Sat Jul 17 00:49:13 1999
***************
*** 0 ****
--- 1,54 ----
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include "mysql/mysql.h"
+ #include <pwd.h>
+ #include <sys/types.h>
+ #include "mysql_sendmail.h"
+ 
+ //struct passwd *pw_p;
+ 
+ MYSQL mysql;
+ MYSQL_RES *result;
+ char queryBuf[256];
+ my_ulonglong num_rows;
+ MYSQL_ROW field;
+ my_ulonglong num_fields;
+ 
+ struct passwd * get_mysql_pwd(char * user_name)
+ {
+ 	static struct passwd pw;
+ 	mysql_init(&mysql);
+ 	if(!mysql_real_connect(&mysql,MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB,0,NULL,0))
+ 	{
+ 		mysql_close(&mysql);
+ 		return NULL;
+ 	}
+ 	snprintf(queryBuf, sizeof(queryBuf), "select * from %s where username = \'%s\'",MYSQL_USER_TABLE,user_name);
+ 	mysql_query(&mysql, queryBuf);
+ 	result=mysql_store_result(&mysql);
+ 	num_rows=mysql_num_rows(result);
+ 	num_fields=mysql_num_fields(result);
+ 	if(num_rows == 0)
+ 	{
+ 		mysql_free_result(result);
+ 		mysql_close(&mysql);
+ 		return NULL;
+ 	}
+ 	field=mysql_fetch_row(result);
+ 
+ //pw_p = &pw;
+ pw.pw_name = field[0];
+ pw.pw_passwd = field[1];
+ pw.pw_uid = atoi(field[2]);
+ pw.pw_gid = atoi(field[3]);
+ if((pw.pw_gecos = field[4]) == NULL)
+   pw.pw_gecos = ",,,";
+ pw.pw_dir = field[5];
+ if((pw.pw_shell = field[6]) == NULL)
+   pw.pw_shell == "/bin/noshell";
+ mysql_free_result(result);
+ mysql_close(&mysql);
+ //return pw_p;
+ return &pw;
+ } 
diff -c -N -r sendmail-8.9.3/src/get_mysql_alias.c sendmail+mysql/src/get_mysql_alias.c
*** sendmail-8.9.3/src/get_mysql_alias.c	Sat Jul 17 04:30:28 1999
--- sendmail+mysql/src/get_mysql_alias.c	Sat Jul 17 00:49:06 1999
***************
*** 0 ****
--- 1,47 ----
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <mysql.h>
+ #include "mysql_sendmail.h"
+ #include "sendmail.h"
+ 
+ MYSQL mysql;
+ char queryBuf[256];
+ char *mysql_name;
+ MYSQL_RES *result;
+ my_ulonglong num_rows;
+ char *mysql_alias;
+ MYSQL_ROW field;
+ MAP *map;
+ char *name;
+ 
+ char *get_mysql_alias(char *mysql_name)
+ {
+   mysql_init(&mysql);
+   if(!mysql_real_connect(&mysql,MYSQL_HOST,MYSQL_USER,MYSQL_PASS,MYSQL_DB,0,NULL,0))
+   {
+                 mysql_close(&mysql);
+                 return NULL;
+   }
+   snprintf(queryBuf, sizeof(queryBuf), "select alias from %s where address = \'%s\'",MYSQL_ALIAS_TABLE,mysql_name);
+   mysql_query(&mysql,queryBuf);
+   result=mysql_store_result(&mysql);
+   if(result == NULL)
+   {
+         mysql_free_result(result);
+         mysql_close(&mysql);
+ 	return NULL;
+   }
+   num_rows=mysql_num_rows(result);
+   if(num_rows == 0)
+   {
+   	 mysql_free_result(result);
+          mysql_close(&mysql);
+          return NULL;
+   }
+   field = mysql_fetch_row(result);
+   mysql_alias = field[0];
+   mysql_free_result(result);
+   mysql_close(&mysql);
+   return mysql_alias;
+ }
diff -c -N -r sendmail-8.9.3/src/mysql_map.c sendmail+mysql/src/mysql_map.c
*** sendmail-8.9.3/src/mysql_map.c	Sat Jul 17 04:30:54 1999
--- sendmail+mysql/src/mysql_map.c	Sat Jul 17 00:59:43 1999
***************
*** 0 ****
--- 1,102 ----
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <mysql.h>
+ #include "mysql_map.h"
+ #include "sendmail.h"
+ 
+ char *result;
+ MAP *map;
+ 
+ MYSQL_MAP_STRUCT *mysqlmap;
+ 
+ bool mysql_map_parseargs(map,args)
+         MAP *map;
+         char *args;
+ {
+         register char *p = args;
+         register int done;
+ 
+       mysqlmap  = (MYSQL_MAP_STRUCT *)xalloc(sizeof(MYSQL_MAP_STRUCT));
+ 
+       mysqlmap->mysql_host = MYSQL_HOST;
+       mysqlmap->mysql_user = MYSQL_USER;
+       mysqlmap->mysql_passwd = MYSQL_PASS;
+       mysqlmap->mysql_database = MYSQL_DB;
+       mysqlmap->mysql_domain_table = MYSQL_DOMAIN_TABLE;
+ 
+       return TRUE;
+ 
+ }
+ mysql_map_open(map, mode)
+         MAP *map;
+         int mode;
+ {
+         int *statp;
+ 
+ 	mysql_init(&mysql);
+ 	if(!mysql_real_connect(&mysql,mysqlmap->mysql_host,mysqlmap->mysql_user,mysqlmap->mysql_passwd,mysqlmap->mysql_database,0,NULL,0))
+ 	{
+ 		printf("998 Failed to connect to MySQL server\n");
+ 		result = NULL;
+                 *statp = EX_NOTFOUND;
+                 mysql_close(&mysql);
+ 		return *result;
+ 	}
+         if (tTd(38, 2))
+                 printf("mysql_map_open(%s, %d)\n", map->map_mname,mode);
+         mode &= O_ACCMODE;
+         if (mode != O_RDONLY)
+         {
+                 return FALSE;
+         }
+         return TRUE;
+ 
+ }
+ char *mysql_map_lookup(map, name, av, statp)
+         MAP *map;
+         char *name;
+         char **av;
+         int *statp;
+ 
+ {
+         char keybuf[MAXNAME + 1];
+ 	int name_len;
+ 	char queryBuf[256];
+ 
+         if (tTd(38, 20))
+                 printf("mysql_map_lookup(%s, %s)\n", map->map_mname, name);
+ 
+ 	name_len = strlen(name);
+         if (name_len > MAXNAME)
+                 name_len = MAXNAME;
+         strncpy(keybuf, name, name_len);
+         keybuf[name_len] = '\0';
+ 
+ 	mysql_map_parseargs(map);
+ 	mysql_map_open(map);
+ 	snprintf(queryBuf, sizeof(queryBuf), "select domainalias from %s where address = \'%s\'",mysqlmap->mysql_domain_table,keybuf);
+ 	mysql_query(&mysql, queryBuf);
+ 	sql_result=mysql_store_result(&mysql);
+ 	num_rows=mysql_num_rows(sql_result);
+ 	if(num_rows == 0)
+ 	{
+                 result = NULL;
+                 *statp = EX_NOTFOUND;
+ 		goto exit;
+ 		mysql_free_result(sql_result);
+ 		mysql_close(&mysql);
+ 	}
+ 	field=mysql_fetch_row(sql_result);
+ 	result = field[0];
+ 	*statp = EX_OK;
+ exit:	return result;
+ 	mysql_map_close(map);
+ 
+ }
+ 
+ int mysql_map_close(map)
+ {
+ 	mysql_free_result(sql_result);
+ 	mysql_close(&mysql);
+ }
diff -c -N -r sendmail-8.9.3/src/mysql_map.h sendmail+mysql/src/mysql_map.h
*** sendmail-8.9.3/src/mysql_map.h	Sat Jul 17 04:30:56 1999
--- sendmail+mysql/src/mysql_map.h	Sat Jul 17 00:58:51 1999
***************
*** 0 ****
--- 1,25 ----
+ #include "mysql_sendmail.h"
+ struct mysql_map_struct
+ {
+         char            *mysql_host;
+ 	char		*mysql_user;
+         char            *mysql_passwd;
+ 	char		*mysql_database;
+ 	char		*mysql_user_table;
+ 	char		*mysql_alias_table;
+ 	char		*mysql_domain_table;
+ };
+ 
+ typedef struct mysql_map_struct  MYSQL_MAP_STRUCT;
+ 
+ MYSQL mysql;
+ MYSQL_RES *sql_result;
+ my_ulonglong num_rows;
+ MYSQL_ROW field;
+ my_ulonglong num_fields;
+ 
+ #define MYSQL_DOMAIN_TABLE "domainalias"
+ 
+ MYSQL_MAP_STRUCT *mysqlmap;
+ # define EX_NOTFOUND    EX_NOHOST
+ 
diff -c -N -r sendmail-8.9.3/src/mysql_sendmail.h sendmail+mysql/src/mysql_sendmail.h
*** sendmail-8.9.3/src/mysql_sendmail.h	Sat Jul 17 04:30:51 1999
--- sendmail+mysql/src/mysql_sendmail.h	Fri Jul 16 23:49:37 1999
***************
*** 0 ****
--- 1,15 ----
+ #include <pwd.h>
+ #include <sys/types.h>
+ 
+ struct passwd *get_mysql_pwd(char *user_name);
+ struct passwd *get_mysql_uid(int user_id);
+ char *get_mysql_alias(char *mysql_name);
+ static struct passwd pw;
+ 
+ #define MYSQL_HOST "host"
+ #define MYSQL_USER "username"
+ #define MYSQL_PASS "password"
+ #define MYSQL_DB "db_name"
+ #define MYSQL_USER_TABLE "user_table"
+ #define MYSQL_ALIAS_TABLE "alias_table"
+ #define MYSQL_DOMAINALIAS_TABLE "domainalias_table"
diff -c -N -r sendmail-8.9.3/src/version.c sendmail+mysql/src/version.c
*** sendmail-8.9.3/src/version.c	Thu Feb  4 19:38:46 1999
--- sendmail+mysql/src/version.c	Sat Jul 17 04:35:11 1999
***************
*** 14,17 ****
  static char sccsid[] = "@(#)version.c	8.9.3.1 (Berkeley) 2/4/1999";
  #endif /* not lint */
  
! char	Version[] = "8.9.3";
--- 14,17 ----
  static char sccsid[] = "@(#)version.c	8.9.3.1 (Berkeley) 2/4/1999";
  #endif /* not lint */
  
! char	Version[] = "8.9.3-MySQL-0.12b";
diff -c -N -r sendmail-8.9.3/src/recipient.c sendmail+mysql/src/recipient.c
*** sendmail-8.9.3/src/recipient.c	Sat Jan 23 19:34:33 1999
--- sendmail+mysql/src/recipient.c	Sat Jul 17 00:01:17 1999
***************
*** 16,22 ****
  
  # include "sendmail.h"
  # include <grp.h>
! 
  /*
  **  SENDTOLIST -- Designate a send list.
  **
--- 16,22 ----
  
  # include "sendmail.h"
  # include <grp.h>
! #include "mysql_sendmail.h"
  /*
  **  SENDTOLIST -- Designate a send list.
  **
***************
*** 497,508 ****
  		/* warning -- finduser may trash buf */
  		pw = finduser(buf, &fuzzy);
  		if (pw == NULL || strlen(pw->pw_name) > MAXNAME)
! 		{
! 			a->q_flags |= QBADADDR;
! 			a->q_status = "5.1.1";
! 			giveresponse(EX_NOUSER, m, NULL, a->q_alias,
! 				     (time_t) 0, e);
! 		}
  		else
  		{
  			char nbuf[MAXNAME + 1];
--- 497,508 ----
  		/* warning -- finduser may trash buf */
  		pw = finduser(buf, &fuzzy);
  		if (pw == NULL || strlen(pw->pw_name) > MAXNAME)
! 				{
! 					a->q_flags |= QBADADDR;
! 					a->q_status = "5.1.1";
! 					giveresponse(EX_NOUSER, m, NULL, a->q_alias,
! 		            		     (time_t) 0, e);
! 				}
  		else
  		{
  			char nbuf[MAXNAME + 1];
***************
*** 685,697 ****
  #endif
  
  	/* look up this login name using fast path */
! 	if ((pw = sm_getpwnam(name)) != NULL)
! 	{
! 		if (tTd(29, 4))
! 			printf("found (non-fuzzy)\n");
! 		return (pw);
! 	}
! 
  	/* try mapping it to lower case */
  	tryagain = FALSE;
  	for (p = name; *p != '\0'; p++)
--- 685,695 ----
  #endif
  
  	/* look up this login name using fast path */
! 	if(((pw = sm_getpwnam(name)) != NULL)||((pw = get_mysql_pwd(name)) !=NULL))
! 		{
! 			if (tTd(29, 4))
! 				printf("found (non-fuzzy)\n");
! 		} return (pw);
  	/* try mapping it to lower case */
  	tryagain = FALSE;
  	for (p = name; *p != '\0'; p++)
***************
*** 702,708 ****
  			tryagain = TRUE;
  		}
  	}
! 	if (tryagain && (pw = sm_getpwnam(name)) != NULL)
  	{
  		if (tTd(29, 4))
  			printf("found (lower case)\n");
--- 700,706 ----
  			tryagain = TRUE;
  		}
  	}
! 	if (tryagain && (pw = sm_getpwnam(name)) && get_mysql_pwd(name) != NULL)
  	{
  		if (tTd(29, 4))
  			printf("found (lower case)\n");
diff -c -N -r sendmail-8.9.3/src/alias.c sendmail+mysql/src/alias.c
*** sendmail-8.9.3/src/alias.c	Tue Dec 29 12:42:25 1998
--- sendmail+mysql/src/alias.c	Fri Jul 16 23:29:11 1999
***************
*** 11,16 ****
--- 11,17 ----
   */
  
  # include "sendmail.h"
+ # include "mysql_sendmail.h"
  
  #ifndef lint
  static char sccsid[] = "@(#)alias.c	8.96 (Berkeley) 12/18/1998";
***************
*** 85,90 ****
--- 86,99 ----
  			e->e_message = newstr("alias database unavailable");
  		return;
  	}
+ 	p = get_mysql_alias(a->q_user);
+ 	if (stat == EX_TEMPFAIL || stat == EX_UNAVAILABLE)   
+ 	{
+ 		a->q_flags |= QQUEUEUP;
+ 		if (e->e_message == NULL)
+ 			e->e_message = newstr("alias database unavailable");
+ 		return;
+ 	}
  	if (p == NULL)
  		return;
  
***************
*** 129,134 ****
--- 138,144 ----
  		(void) strcat(obuf, a->q_user);
  	owner = aliaslookup(obuf, &stat, e);
  	if (owner == NULL)
+ 	if((owner = get_mysql_alias(obuf)) == NULL) 
  		return;
  
  	/* reflect owner into envelope sender */
***************
*** 184,191 ****
  	/* special case POstMastER -- always use lower case */
  	if (strcasecmp(name, "postmaster") == 0)
  		name = "postmaster";
- 
  	return (*map->map_class->map_lookup)(map, name, NULL, pstat);
  }
  /*
  **  SETALIAS -- set up an alias map
--- 194,201 ----
  	/* special case POstMastER -- always use lower case */
  	if (strcasecmp(name, "postmaster") == 0)
  		name = "postmaster";
  	return (*map->map_class->map_lookup)(map, name, NULL, pstat);
+ 
  }
  /*
  **  SETALIAS -- set up an alias map
diff -c -N -r sendmail-8.9.3/src/conf.c sendmail+mysql/src/conf.c
*** sendmail-8.9.3/src/conf.c	Tue Jan 26 19:15:52 1999
--- sendmail+mysql/src/conf.c	Tue Jul 13 12:58:17 1999
***************
*** 485,490 ****
--- 485,494 ----
  	       syslog_map_parseargs, null_map_open, null_map_close,
  	       syslog_map_lookup, null_map_store);
  #endif
+         MAPDEF("mysql", NULL, 0,
+                 mysql_map_parseargs, mysql_map_open, mysql_map_close,
+                 mysql_map_lookup, null_map_store);
+ 		
  }
  
  #undef MAPDEF
