*** cyrus-sasl-1.5.13/lib/Makefile.in	Thu Dec  2 12:11:14 1999
--- cyrus-sasl-1.5.13/lib/Makefile.in	Tue Jan 11 18:16:12 2000
***************
*** 145,152 ****
  
  
! DEFS = @DEFS@ -I. -I$(srcdir) -I..
  CPPFLAGS = @CPPFLAGS@
! LDFLAGS = @LDFLAGS@
! LIBS = @LIBS@
  libsasl_la_OBJECTS =  common.lo saslutil.lo server.lo client.lo md5.lo \
  dlopen.lo checkpw.lo config.lo
--- 145,152 ----
  
  
! DEFS = @DEFS@ -I. -I$(srcdir) -I.. -DHAVE_MYSQL -I/usr/include/mysql
  CPPFLAGS = @CPPFLAGS@
! LDFLAGS = @LDFLAGS@ 
! LIBS = @LIBS@ -lmysqlclient
  libsasl_la_OBJECTS =  common.lo saslutil.lo server.lo client.lo md5.lo \
  dlopen.lo checkpw.lo config.lo
*** cyrus-sasl-1.5.13/lib/checkpw.c	Thu Nov 18 14:11:50 1999
--- cyrus-sasl-1.5.13/lib/checkpw.c	Tue Jan 11 13:00:54 2000
***************
*** 336,339 ****
--- 336,434 ----
  }
  
+ #ifdef HAVE_MYSQL
+ /* DMZ mysql auth 12/29/1999 */
+ #include "mysql.h"
+ //#define QUERY_STRING    "select %s from %s where %s = '%s' and %s = password('%s')"
+ #define QUERY_STRING    "select %s from %s where %s = '%s' and %s = '%s'"
+ 
+ int _sasl_mysql_verify_password(sasl_conn_t *conn __attribute__((unused)),
+                                  const char *userid,
+                                  const char *password,
+                                  const char **reply)
+ {
+   unsigned int numrows;
+   MYSQL mysql,*sock;
+   MYSQL_RES *result;
+   char qbuf[300];
+   char *db_user="",
+        *db_passwd="",
+        *db_host="",
+        *db_uidcol="",
+        *db_pwcol="",
+        *db_database="",
+        *db_table="";
+   sasl_getopt_t *getopt;
+   void *context;
+ 
+   if (!userid || !password) {
+       return SASL_BADPARAM;
+   }
+   if (reply) { *reply = NULL; }
+ 
+   /* check to see if the user configured a mysqluser/passwd/host/etc */
+   if (_sasl_getcallback(conn, SASL_CB_GETOPT, &getopt, &context)
+       == SASL_OK) {
+       getopt(context, NULL, "mysqluser", (const char **) &db_user, NULL);
+       if (!db_user) db_user = "";
+       getopt(context, NULL, "mysqlpasswd", (const char **) &db_passwd, NULL);
+       if (!db_passwd) db_passwd = "";
+       getopt(context, NULL, "mysqlhost", (const char **) &db_host, NULL);
+       if (!db_host) db_host = "";
+       getopt(context, NULL, "mysqldatabase", (const char **) &db_database, NULL);
+       if (!db_database) db_database = "";
+       getopt(context, NULL, "mysqltable", (const char **) &db_table, NULL);
+       if (!db_table) db_table = "";
+       getopt(context, NULL, "mysqluidcol", (const char **) &db_uidcol, NULL);
+       if (!db_uidcol) db_uidcol = "";
+       getopt(context, NULL, "mysqlpwcol", (const char **) &db_pwcol, NULL);
+       if (!db_pwcol) db_pwcol = "";
+   }
+ 
+   //if (!(sock = mysql_connect(&mysql,NULL,0,0)))
+   if (!(sock = mysql_connect(&mysql,db_host,db_user,db_passwd)))
+   {
+     return SASL_FAIL;
+   }
+ 
+   if (mysql_select_db(sock,db_database) < 0)
+   {
+     mysql_close(sock);
+     return SASL_FAIL;
+   }
+   /* select DB_UIDCOL from DB_TABLE where DB_UIDCOL = 'userid' AND DB_PWCOL = password('password') */
+   sprintf(qbuf,QUERY_STRING,db_uidcol,db_table,db_uidcol,userid,db_pwcol,password);
+     if (mysql_query(sock,qbuf) < 0 || !(result=mysql_store_result(sock)))
+     {
+       mysql_close(sock);
+       return SASL_FAIL;
+     }
+ 
+    if (result) //There were some rows found
+    {
+            numrows = mysql_affected_rows(&mysql);
+            if (numrows > 1) // dupes !!
+            {
+                    mysql_free_result(result);
+                    mysql_close(sock);
+                    return SASL_BADAUTH;
+            }
+ 
+            if (numrows == 0) {
+                    mysql_free_result(result);
+                    mysql_close(sock);
+                    return SASL_BADAUTH;
+            }
+ 
+            if (numrows == 1) {
+                    mysql_free_result(result);
+                    mysql_close(sock);
+                    return SASL_OK; }
+    }
+   mysql_free_result(result);
+   mysql_close(sock);
+   return SASL_BADAUTH;
+ }
+ #endif
+ 
  int _sasl_passwd_verify_password(sasl_conn_t *conn __attribute__((unused)),
  				 const char *userid,
*** cyrus-sasl-1.5.13/lib/saslint.h	Mon Sep 20 11:35:01 1999
--- cyrus-sasl-1.5.13/lib/saslint.h	Tue Jan 11 18:15:23 2000
***************
*** 189,192 ****
--- 189,196 ----
  				     const char *service,
  				     const char **reply);
+ extern int _sasl_mysql_verify_password(sasl_conn_t *conn,
+                                    const char *userid,
+                                    const char *password,
+                                    const char **reply);
  extern int _sasl_sasldb_verify_password(sasl_conn_t *conn,
  					const char *userid, 
*** cyrus-sasl-1.5.13/lib/server.c	Thu Dec  2 11:12:06 1999
--- cyrus-sasl-1.5.13/lib/server.c	Tue Jan 11 18:15:33 2000
***************
*** 1098,1101 ****
--- 1098,1107 ----
      } else
  #endif
+ #ifdef HAVE_MYSQL
+ /* Added by dmz 12/29/1999 */
+     if (is_mech(mech, "mysql")) {
+         result = _sasl_mysql_verify_password(conn, user, pass, NULL);
+     } else
+ #endif
  #ifdef HAVE_PWCHECK
      if (is_mech(mech, "pwcheck")) {
