91b2885
diff -up cups-1.4.4/cups/http.c.serialize-gnutls cups-1.4.4/cups/http.c
91b2885
--- cups-1.4.4/cups/http.c.serialize-gnutls	2010-09-17 13:37:01.858871762 +0100
91b2885
+++ cups-1.4.4/cups/http.c	2010-09-17 13:55:22.579871934 +0100
91b2885
@@ -149,7 +149,7 @@ static int		http_write_ssl(http_t *http,
91b2885
 
91b2885
 #  ifdef HAVE_GNUTLS
91b2885
 #    ifdef HAVE_PTHREAD_H
91b2885
-GCRY_THREAD_OPTION_PTHREAD_IMPL;
91b2885
+static pthread_mutex_t gnutls_lock;
91b2885
 #    endif /* HAVE_PTHREAD_H */
91b2885
 
91b2885
 #  elif defined(HAVE_LIBSSL) && defined(HAVE_PTHREAD_H)
91b2885
@@ -1231,7 +1231,7 @@ httpInitialize(void)
91b2885
   */
91b2885
 
91b2885
 #  ifdef HAVE_PTHREAD_H
91b2885
-  gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
91b2885
+  pthread_mutex_init(&gnutls_lock, NULL);
91b2885
 #  endif /* HAVE_PTHREAD_H */
91b2885
 
91b2885
  /*
91b2885
@@ -2228,6 +2228,7 @@ _httpWait(http_t *http,			/* I - Connect
91b2885
     if (SSL_pending((SSL *)(http->tls)))
91b2885
       return (1);
91b2885
 #  elif defined(HAVE_GNUTLS)
91b2885
+    /* lock already held here... */
91b2885
     if (gnutls_record_check_pending(((http_tls_t *)(http->tls))->session))
91b2885
       return (1);
91b2885
 #  elif defined(HAVE_CDSASSL)
91b2885
@@ -2294,6 +2295,8 @@ int					/* O - 1 if data is available, 0
91b2885
 httpWait(http_t *http,			/* I - Connection to server */
91b2885
          int    msec)			/* I - Milliseconds to wait */
91b2885
 {
91b2885
+  int ret;
91b2885
+
91b2885
  /*
91b2885
   * First see if there is data in the buffer...
91b2885
   */
91b2885
@@ -2318,7 +2321,17 @@ httpWait(http_t *http,			/* I - Connecti
91b2885
   * If not, check the SSL/TLS buffers and do a select() on the connection...
91b2885
   */
91b2885
 
91b2885
-  return (_httpWait(http, msec, 1));
91b2885
+#if defined(HAVE_SSL) && defined(HAVE_GNUTLS) && defined(HAVE_PTHREAD_H)
91b2885
+  pthread_mutex_lock(&gnutls_lock);
91b2885
+#endif
91b2885
+
91b2885
+  ret = _httpWait(http, msec, 1);
91b2885
+
91b2885
+#if defined(HAVE_SSL) && defined(HAVE_GNUTLS) && defined(HAVE_PTHREAD_H)
91b2885
+  pthread_mutex_unlock(&gnutls_lock);
91b2885
+#endif
91b2885
+
91b2885
+  return (ret);
91b2885
 }
91b2885
 
91b2885
 
91b2885
@@ -2769,7 +2782,9 @@ http_read_ssl(http_t *http,		/* I - Conn
91b2885
   ssize_t	result;			/* Return value */
91b2885
 
91b2885
 
91b2885
+  pthread_mutex_lock(&gnutls_lock);
91b2885
   result = gnutls_record_recv(((http_tls_t *)(http->tls))->session, buf, len);
91b2885
+  pthread_mutex_unlock(&gnutls_lock);
91b2885
 
91b2885
   if (result < 0 && !errno)
91b2885
   {
91b2885
@@ -3085,6 +3100,7 @@ http_setup_ssl(http_t *http)		/* I - Con
91b2885
     return (-1);
91b2885
   }
91b2885
 
91b2885
+  pthread_mutex_lock(&gnutls_lock);
91b2885
   gnutls_certificate_allocate_credentials(credentials);
91b2885
 
91b2885
   gnutls_init(&(conn->session), GNUTLS_CLIENT);
91b2885
@@ -3104,9 +3120,11 @@ http_setup_ssl(http_t *http)		/* I - Con
91b2885
     free(credentials);
91b2885
     free(conn);
91b2885
 
91b2885
+    pthread_mutex_unlock(&gnutls_lock);
91b2885
     return (-1);
91b2885
   }
91b2885
 
91b2885
+  pthread_mutex_unlock(&gnutls_lock);
91b2885
   conn->credentials = credentials;
91b2885
 
91b2885
 #  elif defined(HAVE_CDSASSL)
91b2885
@@ -3196,9 +3214,11 @@ http_shutdown_ssl(http_t *http)		/* I - 
91b2885
   conn = (http_tls_t *)(http->tls);
91b2885
   credentials = (gnutls_certificate_client_credentials *)(conn->credentials);
91b2885
 
91b2885
+  pthread_mutex_lock(&gnutls_lock);
91b2885
   gnutls_bye(conn->session, GNUTLS_SHUT_RDWR);
91b2885
   gnutls_deinit(conn->session);
91b2885
   gnutls_certificate_free_credentials(*credentials);
91b2885
+  pthread_mutex_unlock(&gnutls_lock);
91b2885
   free(credentials);
91b2885
   free(conn);
91b2885
 
91b2885
@@ -3445,7 +3465,9 @@ http_write_ssl(http_t     *http,	/* I - 
91b2885
 #  elif defined(HAVE_GNUTLS)
91b2885
   ssize_t	result;			/* Return value */
91b2885
 
91b2885
+  pthread_mutex_lock(&gnutls_lock);
91b2885
   result = gnutls_record_send(((http_tls_t *)(http->tls))->session, buf, len);
91b2885
+  pthread_mutex_unlock(&gnutls_lock);
91b2885
 
91b2885
   if (result < 0 && !errno)
91b2885
   {