Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 130701790bf2d95e902edf16031ff596 > files > 10

autofs-5.0.1-0.rc2.164.el5_8.src.rpm

autofs-5.0.1 - add sasl mutex callbacks

From: Ian Kent <raven@themaw.net>

We missed the fact that Cyrus SASL requires the user to provide mutex
handling functions when being used in a threaded environment.

Original patch contributed by Kazuhiro Kikuchi (of Fujitsu), slightly
modified by myself.
---

 modules/cyrus-sasl.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)


--- autofs-5.0.1.orig/modules/cyrus-sasl.c
+++ autofs-5.0.1/modules/cyrus-sasl.c
@@ -936,12 +936,69 @@ void autofs_sasl_dispose(struct lookup_c
 	}
 }
 
+static void *sasl_mutex_new(void)
+{
+	pthread_mutex_t* mutex;
+
+	mutex = malloc(sizeof(pthread_mutex_t));
+	if (!mutex)
+		return 0;
+		
+	pthread_mutex_init(mutex, NULL);
+
+	return (void *) mutex;
+}
+
+static int sasl_mutex_lock(void *mutex __attribute__((unused)))
+{
+	int rc;
+
+	if (!mutex)
+		return SASL_FAIL;
+
+	rc = pthread_mutex_lock((pthread_mutex_t *) mutex);
+
+	return (rc==0 ? SASL_OK : SASL_FAIL);
+}
+
+static int sasl_mutex_unlock(void *mutex __attribute__((unused)))
+{
+	int rc;
+
+	if (!mutex)
+		return SASL_FAIL;
+
+	rc = pthread_mutex_unlock((pthread_mutex_t *) mutex);
+
+	return (rc==0 ? SASL_OK : SASL_FAIL);
+}
+
+static void sasl_mutex_dispose(void *mutex __attribute__((unused)))
+{
+	int rc;
+
+	if (!mutex)
+		return;
+
+	rc = pthread_mutex_destroy((pthread_mutex_t *) mutex);
+	if (rc == 0)
+		free(mutex);
+
+	return;
+}
+
 /*
  * Initialize the sasl callbacks, which increments the global
  * use counter.
  */
 int autofs_sasl_client_init(unsigned logopt)
 {
+
+	sasl_set_mutex(sasl_mutex_new,
+		       sasl_mutex_lock,
+		       sasl_mutex_unlock,
+		       sasl_mutex_dispose);
+
 	/* Start up Cyrus SASL--only needs to be done at library load. */
 	if (sasl_client_init(callbacks) != SASL_OK) {
 		error(logopt, "sasl_client_init failed");