diff -c -N -r sendmail-8.9.3/src/Makefile.m4 patch/Makefile.m4 *** sendmail-8.9.3/src/Makefile.m4 Sat Jan 23 18:51:41 1999 --- patch/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/alias.c patch/alias.c *** sendmail-8.9.3/src/alias.c Tue Dec 29 12:42:25 1998 --- patch/alias.c Tue Jul 13 15:45:10 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,94 ---- e->e_message = newstr("alias database unavailable"); return; } + mysql_name = a->q_user; + if((p = get_mysql_alias(mysql_name)) == NULL) + return; if (p == NULL) return; *************** *** 129,134 **** --- 133,139 ---- (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 */ diff -c -N -r sendmail-8.9.3/src/recipient.c patch/recipient.c *** sendmail-8.9.3/src/recipient.c Sat Jan 23 19:34:33 1999 --- patch/recipient.c Mon Jul 12 15:46:19 1999 *************** *** 16,22 **** # include "sendmail.h" # include ! /* ** SENDTOLIST -- Designate a send list. ** --- 16,22 ---- # include "sendmail.h" # include ! #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,510 ---- /* warning -- finduser may trash buf */ pw = finduser(buf, &fuzzy); if (pw == NULL || strlen(pw->pw_name) > MAXNAME) ! pw = get_mysql_pwd(buf); ! 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,691 **** #endif /* look up this login name using fast path */ ! if ((pw = sm_getpwnam(name)) != NULL) { if (tTd(29, 4)) printf("found (non-fuzzy)\n"); --- 687,693 ---- #endif /* look up this login name using fast path */ ! if (((pw = sm_getpwnam(name)) != NULL) || (get_mysql_pwd(name) != NULL)) { if (tTd(29, 4)) printf("found (non-fuzzy)\n"); *************** *** 702,708 **** tryagain = TRUE; } } ! if (tryagain && (pw = sm_getpwnam(name)) != NULL) { if (tTd(29, 4)) printf("found (lower case)\n"); --- 704,710 ---- 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/get_mysql_pwd.c patch/get_mysql_pwd.c *** sendmail-8.9.3/src/get_mysql_pwd.c Tue Jul 13 16:30:33 1999 --- patch/get_mysql_pwd.c Mon Jul 12 17:20:09 1999 *************** *** 0 **** --- 1,52 ---- + #include + #include + #include + #include "mysql/mysql.h" + #include + #include + #include "mysql_sendmail.h" + + struct passwd *pw_p; + + MYSQL mysql; + MYSQL_RES *result; + char queryBuf[64]; + my_ulonglong num_rows; + MYSQL_ROW field; + my_ulonglong num_fields; + + struct passwd * get_mysql_pwd(char * user_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; + } + sprintf(queryBuf,"select * from %s where username = \'%s\'",MYSQL_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; + } diff -c -N -r sendmail-8.9.3/src/get_mysql_alias.c patch/get_mysql_alias.c *** sendmail-8.9.3/src/get_mysql_alias.c Tue Jul 13 16:30:37 1999 --- patch/get_mysql_alias.c Tue Jul 13 15:53:40 1999 *************** *** 0 **** --- 1,44 ---- + #include + #include + #include + #include + #include "mysql_sendmail.h" + + MYSQL mysql; + char user[32]; + char queryBuf1[128]; + MYSQL_RES *result; + my_ulonglong num_rows; + char *mysql_alias; + MYSQL_ROW field; + + 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; + } + sprintf(queryBuf1,"select alias from %s where address = \'%s\'",MYSQL_ALIAS_TABLE,mysql_name); + mysql_query(&mysql,queryBuf1); + 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 patch/mysql_map.c *** sendmail-8.9.3/src/mysql_map.c Tue Jul 13 16:32:47 1999 --- patch/mysql_map.c Tue Jul 13 15:27:30 1999 *************** *** 0 **** --- 1,100 ---- + #include + #include + #include + #include + #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_table = MYSQL_MAP_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)) + { + result = NULL; + *statp = EX_NOTFOUND; + mysql_close(&mysql); + } + 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[66]; + + 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); + sprintf(queryBuf,"select domainalias from %s where address = \'%s\'",mysqlmap->mysql_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 patch/mysql_map.h *** sendmail-8.9.3/src/mysql_map.h Tue Jul 13 16:32:48 1999 --- patch/mysql_map.h Tue Jul 13 13:56:48 1999 *************** *** 0 **** --- 1,23 ---- + #include "mysql_sendmail.h" + struct mysql_map_struct + { + char *mysql_host; + char *mysql_user; + char *mysql_passwd; + char *mysql_database; + char *mysql_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_MAP_TABLE "domainalias" + + MYSQL_MAP_STRUCT *mysqlmap; + # define EX_NOTFOUND EX_NOHOST + diff -c -N -r sendmail-8.9.3/src/mysql_sendmail.h patch/mysql_sendmail.h *** sendmail-8.9.3/src/mysql_sendmail.h Tue Jul 13 16:30:49 1999 --- patch/mysql_sendmail.h Tue Jul 13 15:44:24 1999 *************** *** 0 **** --- 1,21 ---- + #include + #include + + struct passwd *get_mysql_pwd(char *user_name); + struct passwd *get_mysql_uid(int user_id); + struct passwd pw; + + #define MYSQL_HOST "host" + #define MYSQL_USER "username" + #define MYSQL_PASS "password" + #define MYSQL_DB "mail" + #define MYSQL_TABLE "users_table" + #define MYSQL_ALIAS_TABLE "alias_table" + #define MYSQL_DOMAINALIAS_TABLE "domainalias_table" + + char *mysql_name; + char *alias1; + + char *get_mysql_alias(char *mysql_name); + + diff -c -N -r sendmail-8.9.3/src/conf.c patch/conf.c *** sendmail-8.9.3/src/conf.c Tue Jan 26 19:15:52 1999 --- patch/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 diff -c -N -r sendmail-8.9.3/src/version.c patch/version.c *** sendmail-8.9.3/src/version.c Tue Jul 13 17:01:56 1999 --- patch/version.c Sun Jul 11 16:25:37 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.12a";