apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Havard" <bri...@kheldar.apana.org.au>
Subject Using OpenSSL's des_fcrypt for thread safe crypt()
Date Mon, 25 Apr 2005 12:06:59 GMT
I'd like to add to apr-util the ability to use des_fcrypt from the OpenSSL 
library as a possible thread-safe implementation of crypt() for systems that 
have no crypt_r().

Does anyone have a problem with either the concept or implementation of this?


Index: crypto/apr_md5.c
===================================================================
--- crypto/apr_md5.c	(revision 164544)
+++ crypto/apr_md5.c	(working copy)
@@ -75,6 +75,9 @@
 #if APR_HAVE_PTHREAD_H
 #include <pthread.h>
 #endif
+#if APR_HAVE_OPENSSL_DES_H
+#include <openssl/des.h>
+#endif
 
 /* Constants for MD5Transform routine.
  */
@@ -640,7 +643,8 @@
 
 #if !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
 #if defined(APU_CRYPT_THREADSAFE) || !APR_HAS_THREADS || \
-    defined(CRYPT_R_CRYPTD) || defined(CRYPT_R_STRUCT_CRYPT_DATA)
+    defined(CRYPT_R_CRYPTD) || defined(CRYPT_R_STRUCT_CRYPT_DATA) || \
+    APU_HAVE_DES_FCRYPT
 
 #define crypt_mutex_lock()
 #define crypt_mutex_unlock()
@@ -710,6 +714,11 @@
         memset(&buffer, 0, sizeof(buffer));
         crypt_pw = crypt_r(passwd, hash, &buffer);
         apr_cpystrn(sample, crypt_pw, sizeof(sample) - 1);
+#elif APU_HAVE_DES_FCRYPT
+        char buffer[14];
+
+        crypt_pw = des_fcrypt(passwd, hash, buffer);
+        apr_cpystrn(sample, crypt_pw, sizeof(sample) - 1);
 #else
         /* Do a bit of sanity checking since we know that crypt_r()
          * should always be used for threaded builds on AIX, and
Index: include/apu.h.in
===================================================================
--- include/apu.h.in	(revision 164544)
+++ include/apu.h.in	(working copy)
@@ -84,6 +84,7 @@
 #define APU_HAVE_APR_ICONV     @have_apr_iconv@
 #define APU_HAVE_ICONV         @have_iconv@
 #define APR_HAS_XLATE          (APU_HAVE_APR_ICONV || APU_HAVE_ICONV)
+#define APR_HAVE_OPENSSL_DES_H @openssl_desh@
 
 #endif /* APU_H */
 /** @} */
Index: configure.in
===================================================================
--- configure.in	(revision 164544)
+++ configure.in	(working copy)
@@ -124,6 +124,13 @@
 APU_FIND_EXPAT
 APU_FIND_ICONV
 
+APR_FLAG_HEADERS(openssl/des.h)
+
+AC_CHECK_LIB(crypto, DES_fcrypt, [
+  APR_ADDTO(APRUTIL_EXPORT_LIBS, -lcrypto)
+  AC_DEFINE(APU_HAVE_DES_FCRYPT, 1, [Define if OpenSSL DES_fcrypt is available])
+])
+
 AC_SEARCH_LIBS(crypt, crypt ufc)
 AC_MSG_CHECKING(if system crypt() function is threadsafe)
 if test "x$apu_crypt_threadsafe" = "x1"; then
@@ -158,6 +165,7 @@
 AC_SUBST(APRUTIL_LDFLAGS)
 AC_SUBST(APRUTIL_LIBS)
 AC_SUBST(LDFLAGS)
+AC_SUBST(openssl_desh)
 
 dnl copy apr's rules.mk into our build directory.
 if test ! -d ./build; then

-- 
 ______________________________________________________________________________
 |  Brian Havard                 |  "He is not the messiah!                   |
 |  brianh@kheldar.apana.org.au  |  He's a very naughty boy!" - Life of Brian |
 ------------------------------------------------------------------------------


Mime
View raw message