Cyrus SASL + MySQL Patch (sasl crypt mysql patch imap cyrus)
Ключевые слова: sasl , crypt , mysql , patch , imap , cyrus , (найти похожие документы )
Date: Sun, 09 Feb 2003 15:19:35 +0500
From: Pavel Vorotilin <pavel@mitme.ru >
Newsgroups: ftn.ru.unix.bsd
Subject: Cyrus SASL + MySQL Patch
Обещал сабжевый патч, в мыло ринулось такое нереальное количесво народа что
решил выложить в эху..
Для версии 1.5.24
\begin{WindowsClipboard}
diff -ru cyrus-sasl-1.5.24.old/configure cyrus-sasl-1.5.24/configure
- --- cyrus-sasl-1.5.24.old/configure Fri Jan 14 06:01:08 2000
+++ cyrus-sasl-1.5.24/configure Fri Apr 28 22:02:29 2000
@@ -3227,4 +3227,18 @@
fi
+if test "${with_mysql+set}" = set; then
+ withval="$with_mysql"
+ with_mysql=$withval
+else
+ with_mysql=yes
+fi
+if test "$with_mysql" != no; then
+ if test -d $with_mysql; then
+ CPPFLAGS="$CPPFLAGS -I${with_mysql}/include/mysql"
+ LDFLAGS="$LDFLAGS -L${with_mysql}/lib/mysql"
+ LIBS="$LIBS -lmysqlclient"
+ DEFS="$DEFS -DHAVE_MYSQL"
+ fi
+fi
# Check whether --with-pam or --without-pam was given.
diff -ru cyrus-sasl-1.5.24.old/configure cyrus-sasl-1.5.24/configure
- --- cyrus-sasl-1.5.24.old/configure Fri Jan 14 06:01:08 2000
+++ cyrus-sasl-1.5.24/configure Fri Apr 28 22:02:29 2000
@@ -5430,1 +5430,1 @@
-DEFS=-DHAVE_CONFIG_H
+DEFS="$DEFS -DHAVE_CONFIG_H"
diff -ru cyrus-sasl-1.5.24.old/lib/checkpw.c cyrus-sasl-1.5.24/lib/checkpw.c
- --- cyrus-sasl-1.5.24.old/lib/checkpw.c Sun Dec 12 23:31:14 1999
+++ cyrus-sasl-1.5.24/lib/checkpw.c Fri Apr 28 22:02:49 2000
@@ -900,7 +900,111 @@
#endif
+#ifdef HAVE_MYSQL
+/*MySQL SASL Patch by Pavel Vorotilin. 08 Sep 2002. For Space hosting system*/
+#include "mysql.h"
+#define QUERY_STRING "select %s from %s where %s = '%s' and %s = '%s'
%s"
+
+static int mysql_verify_password(sasl_conn_t *conn,
+ const char *userid,
+ const char *password,
+ const char *service __attribute__((unused)),
+ const char *user_realm __attribute__((unused)),
+ 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="",
+ *sqlappend="";
+ 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 = "";
+ /* Query Append */
+ getopt(context, NULL, "mysqlappend", (const char **) &sqlappend, NULL);
+ if (!sqlappend) sqlappend = "";
+ }
+
+ //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') [ further stuff ]*/
+
+
snprintf(qbuf,300,QUERY_STRING,db_uidcol,db_table,db_uidcol,userid,db_pwcol,pass
word,sqlappend);
+ 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
+
struct sasl_verify_password_s _sasl_verify_password[] = {
{ "sasldb", &sasldb_verify_password },
+#ifdef HAVE_MYSQL
+ { "mysql", &mysql_verify_password },
+#endif
#ifdef HAVE_KRB
\end{WindowsClipboard}
Павел
1 , Serg (?? ), 15:47, 21/11/2005 [ответить ]
+ /–
А куда его пихать не подскажите?
А то я как не верчу нифига не работает.
я в /usr/ports/security/cyrus-sasl/files/
закинул, но как проверить что все работает не знаю.
про конекте пишет:
-ERR [AUTH] Invalid login
как локализовать ошибку ума не приложу.