diff --git a/configure.in b/configure.in
index 7c217dd..562834c 100644
--- a/configure.in
+++ b/configure.in
@@ -233,7 +233,7 @@ AC_ARG_ENABLE(pam,
 
 pam_status="no"
 if test "$enable_pam" != "no"; then
-	AC_CHECK_HEADER(security/pam_modules.h, have_pam=yes, have_pam=no)
+	AC_CHECK_HEADERS(security/pam_modules.h pam/pam_modules.h, have_pam=yes, have_pam=no)
 	if test "$enable_pam" = "yes" -a "$have_pam" = "no"; then
 		AC_MSG_ERROR(The PAM headers are missing)
 	elif test "$have_pam" = "yes"; then
diff --git a/pam/gkr-pam-module.c b/pam/gkr-pam-module.c
index d6fc17d..74c6923 100644
--- a/pam/gkr-pam-module.c
+++ b/pam/gkr-pam-module.c
@@ -33,8 +33,14 @@
 
 #include "daemon/control/gkd-control-codes.h"
 
+#ifdef HAVE_SECURITY_PAM_MODULES_H
 #include <security/pam_appl.h>
 #include <security/pam_modules.h>
+#endif
+#ifdef HAVE_PAM_PAM_MODULES_H
+#include <pam/pam_appl.h>
+#include <pam/pam_modules.h>
+#endif
 
 #include <sys/types.h>
 #include <sys/stat.h>
