SOURCES: cyrus-sasl-cryptedpw.patch (NEW) - crypted passwd in mysq...

romke romke at pld-linux.org
Thu Jul 21 00:29:26 CEST 2005


Author: romke                        Date: Wed Jul 20 22:29:26 2005 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- crypted passwd in mysql or pgsql

---- Files affected:
SOURCES:
   cyrus-sasl-cryptedpw.patch (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/cyrus-sasl-cryptedpw.patch
diff -u /dev/null SOURCES/cyrus-sasl-cryptedpw.patch:1.1
--- /dev/null	Thu Jul 21 00:29:26 2005
+++ SOURCES/cyrus-sasl-cryptedpw.patch	Thu Jul 21 00:29:21 2005
@@ -0,0 +1,188 @@
+diff -ur cyrus-sasl-2.1.19.orig/Makefile.in cyrus-sasl-2.1.19/Makefile.in
+--- cyrus-sasl-2.1.19.orig/Makefile.in        2005-07-04 23:59:31.000000000 +0200
++++ cyrus-sasl-2.1.19/Makefile.in 2005-07-05 00:04:27.000000000 +0200
+@@ -134,7 +134,7 @@
+ JAVA_TRUE = @JAVA_TRUE@
+ LDFLAGS = @LDFLAGS@
+ LIBOBJS = @LIBOBJS@
+-LIBS = @LIBS@
++LIBS = -lcrypt @LIBS@
+ LIBTOOL = @LIBTOOL@
+ LIB_CRYPT = @LIB_CRYPT@
+ LIB_DES = @LIB_DES@
+diff -ruN cyrus-sasl-2.1.20-orig/doc/options.html cyrus-sasl-2.1.20/doc/options.html
+--- cyrus-sasl-2.1.20-orig/doc/options.html	2004-05-27 18:02:58.000000000 +0200
++++ cyrus-sasl-2.1.20/doc/options.html	2005-07-10 17:17:38.000000000 +0200
+@@ -103,6 +103,14 @@
+ <TD>sasldb_path</TD><TD>sasldb plugin</TD>
+ <TD>Path to sasldb file</TD><TD><tt>/etc/sasldb2</tt> (system dependant)</TD>
+ <TR>
++<TD>password_format</TD><TD></TD>
++<TD>Method of password storage (possible values: 'plain', 'crypt', 'crypt_trad').
++Default 'plain' is down-compatible with earlier versions. 'crypt_trad'
++uses old crypt format of 2 chars salt, 'crypt' automagically recognizes crypt
++formats from md5 crypt, blowfish crypt and old crypt (2 chars salt).</TD>
++<TD>plain</TD>
++</TR>
++<TR>
+ <TD>sql_engine</TD><TD>SQL plugin</TD>
+ <TD>Name of SQL engine to use (possible values: 'mysql', 'pgsql', 'sqlite').</TD>
+ <TD><tt>mysql</tt></TD>
+diff -ruN cyrus-sasl-2.1.20-orig/lib/checkpw.c cyrus-sasl-2.1.20/lib/checkpw.c
+--- cyrus-sasl-2.1.20-orig/lib/checkpw.c	2004-03-17 14:58:13.000000000 +0100
++++ cyrus-sasl-2.1.20/lib/checkpw.c	2005-07-10 16:17:11.000000000 +0200
+@@ -94,6 +94,23 @@
+ # endif
+ #endif
+ 
++/******************************
++ * crypt(3) patch start       *
++ ******************************/
++char *crypt(const char *key, const char *salt);
++
++/* cleartext password formats */
++#define PASSWORD_FORMAT_CLEARTEXT 1
++#define PASSWORD_FORMAT_CRYPT 2
++#define PASSWORD_FORMAT_CRYPTTRAD 3
++#define PASSWORD_SALT_BUF_LEN 22
++
++/* weeds out crypt(3) password's salt */
++int _sasl_get_salt (char *dest, char *src, int format);
++
++/******************************
++ * crypt(3) patch stop        *
++ ******************************/
+ 
+ /* we store the following secret to check plaintext passwords:
+  *
+@@ -143,7 +160,51 @@
+ 				       "*cmusaslsecretPLAIN",
+ 				       NULL };
+     struct propval auxprop_values[3];
+-    
++
++	/******************************
++	 * crypt(3) patch start       *
++	 * for password format check  *
++	 ******************************/
++    sasl_getopt_t *getopt;
++    void *context;
++    const char *p = NULL;
++	/**
++	 * MD5: 12 char salt
++	 * BLOWFISH: 16 char salt
++	 */
++	char salt[PASSWORD_SALT_BUF_LEN];
++	int password_format;
++
++	/* get password format from auxprop configuration */
++	if (_sasl_getcallback(conn, SASL_CB_GETOPT, &getopt, &context) == SASL_OK) {
++		getopt(context, NULL, "password_format", &p, NULL);
++	}
++
++	/* set password format */
++	if (p) {
++		/*
++		memset(pass_format_str, '\0', PASSWORD_FORMAT_STR_LEN);
++		strncpy(pass_format_str, p, (PASSWORD_FORMAT_STR_LEN - 1));
++		*/
++		/* modern, modular crypt(3) */
++		if (strncmp(p, "crypt", 11) == 0)
++			password_format = PASSWORD_FORMAT_CRYPT;
++		/* traditional crypt(3) */
++		else if (strncmp(p, "crypt_trad", 11) == 0)
++			password_format = PASSWORD_FORMAT_CRYPTTRAD;
++		/* cleartext password */
++		else
++			password_format = PASSWORD_FORMAT_CLEARTEXT;
++	} else {
++		/* cleartext password */
++		password_format = PASSWORD_FORMAT_CLEARTEXT;
++	}
++
++	/******************************
++	 * crypt(3) patch stop        *
++	 * for password format check  *
++	 ******************************/
++
+     if (!conn || !userstr)
+ 	return SASL_BADPARAM;
+ 
+@@ -180,14 +241,31 @@
+ 	goto done;
+     }
+ 
+-    /* At the point this has been called, the username has been canonified
+-     * and we've done the auxprop lookup.  This should be easy. */
+-    if(auxprop_values[0].name
+-       && auxprop_values[0].values
+-       && auxprop_values[0].values[0]
+-       && !strcmp(auxprop_values[0].values[0], passwd)) {
+-	/* We have a plaintext version and it matched! */
+-	return SASL_OK;
++
++	/******************************
++	 * crypt(3) patch start       *
++	 ******************************/	
++
++	/* get salt */
++	_sasl_get_salt(salt, (char *) auxprop_values[0].values[0], password_format);
++	
++	/* crypt(3)-ed password? */
++	if (password_format != PASSWORD_FORMAT_CLEARTEXT) {
++		/* compare password */
++		if (auxprop_values[0].name && auxprop_values[0].values && auxprop_values[0].values[0] && strcmp(crypt(passwd, salt), auxprop_values[0].values[0]) == 0)
++			return SASL_OK;
++		else
++			ret = SASL_BADAUTH;
++	}
++	else if (password_format == PASSWORD_FORMAT_CLEARTEXT) {
++		/* compare passwords */
++		if (auxprop_values[0].name && auxprop_values[0].values && auxprop_values[0].values[0] && strcmp(auxprop_values[0].values[0], passwd) == 0)
++			return SASL_OK;
++		else
++			ret = SASL_BADAUTH;
++	/******************************
++	 * crypt(3) patch stop        *
++	 ******************************/
+     } else if(auxprop_values[1].name
+ 	      && auxprop_values[1].values
+ 	      && auxprop_values[1].values[0]) {
+@@ -975,3 +1053,37 @@
+ #endif     
+     { NULL, NULL }
+ };
++
++/* weeds out crypt(3) password's salt */
++int _sasl_get_salt (char *dest, char *src, int format) {
++	int num;	/* how many characters is salt long? */
++	switch (format) {
++		case PASSWORD_FORMAT_CRYPT:
++			/* md5 crypt */
++			if (src[1] == '1')
++				num = 12;
++			/* blowfish crypt */
++			else if (src[1] == '2')
++				num = (src[1] == '2' && src[2] == 'a') ? 17 : 16;
++			/* traditional crypt */
++			else
++				num = 2;
++			break;
++	
++		case PASSWORD_FORMAT_CRYPTTRAD:
++			num = 2;
++			break;
++
++		default:
++			return 1;
++	}
++
++	/* destroy destination */
++	memset(dest, '\0', (num + 1));
++
++	/* copy salt to destination */
++	strncpy(dest, src, num);
++
++	return 1;
++}
++
================================================================



More information about the pld-cvs-commit mailing list