Description: Making pamslurm use libslurm shipped with the libslurm package
 The pam_slurm module dlopen libslurm.so that is a link usually shipped
 with the dev package (libslurm-dev), this patch modify the source to
 open the libslur.so.version shipped with the libslurm package.

---
Origin: maintainer
Forwarded: by mail
Reviewed-By: Moe Jette <jette@schedmd.com>
Last-Update: 2011-12-21

--- slurm-llnl-2.3.2.orig/contribs/pam/pam_slurm.c
+++ slurm-llnl-2.3.2/contribs/pam/pam_slurm.c
@@ -30,6 +30,9 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 \*****************************************************************************/
 
+#if HAVE_CONFIG_H
+#  include "config.h"
+#endif
 
 #include <ctype.h>
 #include <errno.h>
@@ -357,12 +360,42 @@ _send_denial_msg(pam_handle_t *pamh, str
  */
 extern void libpam_slurm_init (void)
 {
+	char libslurmname[64];
+
 	if (slurm_h)
 		return;
 
-	if (!(slurm_h = dlopen("libslurm.so", RTLD_NOW|RTLD_GLOBAL)))
-		_log_msg (LOG_ERR, "Unable to dlopen libslurm: %s\n",
+	/* First try to use the same libslurm version ("libslurm.so.24.0.0"),
+	 * Second try to match the major version number ("libslurm.so.24"),
+	 * Otherwise use "libslurm.so" */
+
+	if (snprintf(libslurmname, sizeof(libslurmname),
+		"libslurm.so.%d.%d.%d", SLURM_API_CURRENT, SLURM_API_REVISION,
+			SLURM_API_AGE) >= sizeof(libslurmname) ) {
+		_log_msg (LOG_ERR, "Unable to write libslurmname\n");
+	}
+	else {
+		if (!(slurm_h = dlopen(libslurmname, RTLD_NOW|RTLD_GLOBAL))) {
+			_log_msg (LOG_INFO, "Unable to dlopen %s: %s\n",
+				libslurmname, dlerror ());
+		}
+	}
+
+	if (snprintf(libslurmname, sizeof(libslurmname), "libslurm.so.%d",
+		SLURM_API_CURRENT) >= sizeof(libslurmname) ) {
+		_log_msg (LOG_ERR, "Unable to write libslurmname\n");
+	}
+	else {
+		if (!(slurm_h = dlopen(libslurmname, RTLD_NOW|RTLD_GLOBAL))) {
+			_log_msg (LOG_INFO, "Unable to dlopen %s: %s\n",
+				libslurmname, dlerror ());
+		}
+	}
+
+	if (!(slurm_h = dlopen("libslurm.so", RTLD_NOW|RTLD_GLOBAL))) {
+		_log_msg (LOG_ERR, "Unable to dlopen libslurm.so: %s\n",
 			  dlerror ());
+	}
 
 	return;
 }
