--- modules/pam_group/pam_group.c.orig	2014-01-11 12:45:09.910924835 +0100
+++ modules/pam_group/pam_group.c	2014-01-11 12:46:31.598451777 +0100
@@ -656,7 +656,11 @@ static int check_account(pam_handle_t *p
 	}
 	/* If buffer starts with @, we are using netgroups */
 	if (buffer[0] == '@')
+#ifdef HAVE_INNETGR
 	  good &= innetgr (&buffer[1], NULL, user, NULL);
+#else
+	  good = 0;
+#endif
 	/* otherwise, if the buffer starts with %, it's a UNIX group */
 	else if (buffer[0] == '%')
           good &= pam_modutil_user_in_group_nam_nam(pamh, user, &buffer[1]);
--- modules/pam_time/pam_time.c.orig	2014-01-11 12:47:00.534638461 +0100
+++ modules/pam_time/pam_time.c	2014-01-11 12:47:35.470863839 +0100
@@ -555,7 +555,11 @@ check_account(pam_handle_t *pamh, const
 	  }
 	  /* If buffer starts with @, we are using netgroups */
 	  if (buffer[0] == '@')
+#ifdef HAVE_INNETGR
 	    good &= innetgr (&buffer[1], NULL, user, NULL);
+#else
+	    good = 0;
+#endif
 	  else
 	    good &= logic_field(pamh, user, buffer, count, is_same);
 	  D(("with user: %s", good ? "passes":"fails" ));
--- modules/pam_succeed_if/pam_succeed_if.c.orig	2014-01-11 12:47:51.391966546 +0100
+++ modules/pam_succeed_if/pam_succeed_if.c	2014-01-11 12:48:31.519225435 +0100
@@ -233,16 +233,20 @@ evaluate_notingroup(pam_handle_t *pamh,
 static int
 evaluate_innetgr(const char *host, const char *user, const char *group)
 {
+#ifdef HAVE_INNETGR
 	if (innetgr(group, host, user, NULL) == 1)
 		return PAM_SUCCESS;
+#endif
 	return PAM_AUTH_ERR;
 }
 /* Return PAM_SUCCESS if the (host,user) is NOT in the netgroup. */
 static int
 evaluate_notinnetgr(const char *host, const char *user, const char *group)
 {
+#ifdef HAVE_INNETGR
 	if (innetgr(group, host, user, NULL) == 0)
 		return PAM_SUCCESS;
+#endif
 	return PAM_AUTH_ERR;
 }
 
--- modules/pam_lastlog/pam_lastlog.c.orig	2014-01-11 12:56:15.735248391 +0100
+++ modules/pam_lastlog/pam_lastlog.c	2014-01-11 12:57:33.142756424 +0100
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <syslog.h>
 #include <unistd.h>
+#include <paths.h>
 
 #if defined(hpux) || defined(sunos) || defined(solaris)
 # ifndef _PATH_LASTLOG
@@ -403,7 +404,9 @@ last_login_write(pam_handle_t *pamh, int
 
     if (announce & LASTLOG_WTMP) {
 	/* write wtmp entry for user */
+#ifdef HAVE_LOGWTMP
 	logwtmp(last_login.ll_line, user, remote_host);
+#endif
     }
 
     /* cleanup */
@@ -713,7 +716,9 @@ pam_sm_close_session (pam_handle_t *pamh
     terminal_line = get_tty(pamh);
 
     /* Wipe out utmp logout entry */
+#ifdef HAVE_LOGWTMP
     logwtmp(terminal_line, "", "");
+#endif
 
     return PAM_SUCCESS;
 }
--- modules/pam_rhosts/pam_rhosts.c.orig	2014-01-11 12:58:40.263196779 +0100
+++ modules/pam_rhosts/pam_rhosts.c	2014-01-11 12:59:25.182491398 +0100
@@ -113,8 +113,10 @@ int pam_sm_authenticate (pam_handle_t *p
 
 #ifdef HAVE_RUSEROK_AF
     retval = ruserok_af (rhost, as_root, ruser, luser, PF_UNSPEC);
-#else
+#elif HAVE_RUSEROK
     retval = ruserok (rhost, as_root, ruser, luser);
+#else
+    retval = 1;
 #endif
     if (retval != 0) {
       if (!opt_silent || opt_debug)
--- configure.in.orig	2014-01-11 13:09:06.207296880 +0100
+++ configure.in	2014-01-11 13:14:56.237585380 +0100
@@ -404,7 +404,7 @@ AS_IF([test "x$ac_cv_header_xcrypt_h" =
   [crypt_libs="crypt"])
 
 BACKUP_LIBS=$LIBS
-AC_SEARCH_LIBS([crypt],[$crypt_libs], LIBCRYPT="-l$ac_lib", LIBCRYPT="")
+AC_SEARCH_LIBS([crypt],[$crypt_libs], [test -n "$ac_lib" && LIBCRYPT="-l$ac_lib"], LIBCRYPT="")
 AC_CHECK_FUNCS(crypt_r crypt_gensalt_r)
 LIBS=$BACKUP_LIBS
 AC_SUBST(LIBCRYPT)