Jiří Popelka 547aaa
diff -up cups-1.4.2/config-scripts/cups-ssl.m4.gnutls-gcrypt-threads cups-1.4.2/config-scripts/cups-ssl.m4
Jiří Popelka 547aaa
--- cups-1.4.2/config-scripts/cups-ssl.m4.gnutls-gcrypt-threads	2010-02-15 12:21:32.000000000 +0100
Jiří Popelka 547aaa
+++ cups-1.4.2/config-scripts/cups-ssl.m4	2010-02-15 12:24:57.000000000 +0100
Jiří Popelka 547aaa
@@ -61,7 +61,7 @@ if test x$enable_ssl != xno; then
Jiří Popelka 547aaa
     if test "x${SSLLIBS}" = "x" -a "x${enable_gnutls}" != "xno" -a "x$PKGCONFIG" != x; then
Jiří Popelka 547aaa
     	AC_PATH_PROG(LIBGNUTLSCONFIG,libgnutls-config)
Jiří Popelka 547aaa
 	if $PKGCONFIG --exists gnutls; then
Jiří Popelka 547aaa
-	    SSLLIBS=`$PKGCONFIG --libs gnutls`
Jiří Popelka 547aaa
+	    SSLLIBS="`$PKGCONFIG --libs gnutls` -lgcrypt"
Jiří Popelka 547aaa
 	    SSLFLAGS=`$PKGCONFIG --cflags gnutls`
Jiří Popelka 547aaa
 	    AC_DEFINE(HAVE_SSL)
Jiří Popelka 547aaa
 	    AC_DEFINE(HAVE_GNUTLS)
Tim Waugh f6c821
diff -up cups-1.4.2/cups/http.c.gnutls-gcrypt-threads cups-1.4.2/cups/http.c
Jiří Popelka 547aaa
--- cups-1.4.2/cups/http.c.gnutls-gcrypt-threads	2010-02-15 12:21:32.000000000 +0100
Jiří Popelka 547aaa
+++ cups-1.4.2/cups/http.c	2010-02-15 12:25:57.000000000 +0100
Jiří Popelka 547aaa
@@ -1161,6 +1161,12 @@ httpHead(http_t     *http,		/* I - Conne
Tim Waugh f6c821
   return (http_send(http, HTTP_HEAD, uri));
Tim Waugh f6c821
 }
Tim Waugh f6c821
 
Tim Waugh f6c821
+#ifdef HAVE_GNUTLS
Jiří Popelka 547aaa
+/* We always have to initialize threading in gcrypt here in libcups
Jiří Popelka 547aaa
+ * even if cupsd is configured without threading, because an
Jiří Popelka 547aaa
+ * application using libcups may be using threads itself. */
Tim Waugh f6c821
+GCRY_THREAD_OPTION_PTHREAD_IMPL;
Tim Waugh f6c821
+#endif
Tim Waugh f6c821
 
Tim Waugh f6c821
 /*
Tim Waugh f6c821
  * 'httpInitialize()' - Initialize the HTTP interface library and set the
Jiří Popelka 547aaa
@@ -1205,6 +1211,7 @@ httpInitialize(void)
Tim Waugh f6c821
 #endif /* WIN32 */
Tim Waugh f6c821
 
Tim Waugh f6c821
 #ifdef HAVE_GNUTLS
Tim Waugh f6c821
+  gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
Tim Waugh f6c821
   gnutls_global_init();
Tim Waugh f6c821
 #endif /* HAVE_GNUTLS */
Tim Waugh f6c821
 
Tim Waugh f6c821
diff -up cups-1.4.2/cups/http-private.h.gnutls-gcrypt-threads cups-1.4.2/cups/http-private.h
Jiří Popelka 547aaa
--- cups-1.4.2/cups/http-private.h.gnutls-gcrypt-threads	2009-04-07 17:48:14.000000000 +0200
Jiří Popelka 547aaa
+++ cups-1.4.2/cups/http-private.h	2010-02-15 12:26:30.000000000 +0100
Tim Waugh f6c821
@@ -98,6 +98,8 @@ extern BIO_METHOD *_httpBIOMethods(void)
Tim Waugh f6c821
  * The GNU TLS library is more of a "bare metal" SSL/TLS library...
Tim Waugh f6c821
  */
Tim Waugh f6c821
 #    include <gnutls/gnutls.h>
Tim Waugh f6c821
+#    include <gcrypt.h>
Tim Waugh f6c821
+#    include <pthread.h>
Tim Waugh f6c821
 
Tim Waugh f6c821
 typedef struct
Tim Waugh f6c821
 {
Tim Waugh f6c821
diff -up cups-1.4.2/scheduler/server.c.gnutls-gcrypt-threads cups-1.4.2/scheduler/server.c
Jiří Popelka 547aaa
--- cups-1.4.2/scheduler/server.c.gnutls-gcrypt-threads	2008-09-11 00:05:29.000000000 +0200
Jiří Popelka 547aaa
+++ cups-1.4.2/scheduler/server.c	2010-02-15 12:24:13.000000000 +0100
Jiří Popelka 547aaa
@@ -35,6 +35,9 @@
Tim Waugh f6c821
  */
Tim Waugh f6c821
 
Tim Waugh f6c821
 static int	started = 0;
Jiří Popelka 547aaa
+#if !defined(HAVE_LIBSSL) && defined(HAVE_GNUTLS) && defined(HAVE_PTHREAD_H)
Tim Waugh f6c821
+GCRY_THREAD_OPTION_PTHREAD_IMPL;
Tim Waugh f6c821
+#endif
Tim Waugh f6c821
 
Jiří Popelka 547aaa
 
Tim Waugh f6c821
 /*
Jiří Popelka 547aaa
@@ -75,7 +78,9 @@ cupsdStartServer(void)
Tim Waugh f6c821
  /*
Tim Waugh f6c821
   * Initialize the encryption libraries...
Tim Waugh f6c821
   */
Tim Waugh f6c821
-
Jiří Popelka 547aaa
+#ifdef HAVE_PTHREAD_H
Tim Waugh f6c821
+  gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
Jiří Popelka 547aaa
+#endif /* HAVE_PTHREAD_H */
Tim Waugh f6c821
   gnutls_global_init();
Tim Waugh f6c821
 #endif /* HAVE_LIBSSL */
Tim Waugh f6c821