aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Hrozek <jakub.hrozek@posteo.se>2015-10-30 10:10:01 +0100
committerAndreas Schneider <asn@samba.org>2015-12-10 13:31:20 +0100
commita3e52ead6001342dde59bc65806e4d2e850d8a5b (patch)
treeefaa97b8e3c1acec998e5a0e26eeb895d5968fac
parent6928549dc6da0b059305bc2e4d34f4e83beeb74f (diff)
downloadpam_wrapper-a3e52ead6001342dde59bc65806e4d2e850d8a5b.tar.gz
pam_wrapper-a3e52ead6001342dde59bc65806e4d2e850d8a5b.tar.xz
pam_wrapper-a3e52ead6001342dde59bc65806e4d2e850d8a5b.zip
pwrap: Build on FreeBSD
With this patch, pam_wrapper builds on FreeBSD, but doesn't work (yet)
-rw-r--r--ConfigureChecks.cmake8
-rw-r--r--config.h.cmake2
-rw-r--r--include/pwrap_compat.h22
-rw-r--r--src/CMakeLists.txt8
-rw-r--r--src/modules/pam_get_items.c17
-rw-r--r--src/modules/pam_matrix.c30
-rw-r--r--src/modules/pam_set_items.c17
-rw-r--r--src/pam_wrapper.c6
-rw-r--r--tests/CMakeLists.txt7
-rw-r--r--tests/test_pam_wrapper.c35
10 files changed, 142 insertions, 10 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index e26494f..ca9626e 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -38,15 +38,21 @@ endfunction()
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
check_include_file(unistd.h HAVE_UNISTD_H)
check_include_file(security/pam_appl.h HAVE_SECURITY_PAM_APPL_H)
+check_include_file(security/pam_modules.h HAVE_SECURITY_PAM_MODULES_H)
+check_include_file(security/pam_ext.h HAVE_SECURITY_PAM_EXT_H)
# FUNCTIONS
check_function_exists(strncpy HAVE_STRNCPY)
check_function_exists(vsnprintf HAVE_VSNPRINTF)
check_function_exists(snprintf HAVE_SNPRINTF)
-# FUNCTIONS
+# LIBRARIES
find_library(PAM_LIBRARY NAMES libpam.so.0 pam)
set(PAM_LIBRARY ${PAM_LIBRARY})
+find_library(PAM_MISC_LIBRARY NAMES pam_misc)
+if (PAM_MISC_LIBRARY)
+ set(HAVE_PAM_MISC TRUE)
+endif()
# OPTIONS
diff --git a/config.h.cmake b/config.h.cmake
index 921fbbe..e864bee 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -17,6 +17,8 @@
#cmakedefine HAVE_SYS_TYPES_H 1
#cmakedefine HAVE_UNISTD_H 1
#cmakedefine HAVE_SECURITY_PAM_APPL_H 1
+#cmakedefine HAVE_SECURITY_PAM_MODULES_H 1
+#cmakedefine HAVE_SECURITY_PAM_EXT_H 1
/*************************** FUNCTIONS ***************************/
diff --git a/include/pwrap_compat.h b/include/pwrap_compat.h
new file mode 100644
index 0000000..45d7885
--- /dev/null
+++ b/include/pwrap_compat.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2015 Andreas Schneider <asn@samba.org>
+ * Copyright (c) 2015 Jakub Hrozek <jakub.hrozek@posteo.se>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* OpenPAM doesn't define PAM_BAD_ITEM */
+#ifndef PAM_BAD_ITEM
+#define PAM_BAD_ITEM PAM_SYSTEM_ERR
+#endif /* PAM_BAD_ITEM */
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1455bb3..7afb598 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -46,9 +46,11 @@ install(
)
set(PAM_MODULES pam_matrix pam_get_items pam_set_items)
-set(PAM_LIBRARIES
- pam
- pam_misc)
+
+set(PAM_LIBRARIES pam)
+if (HAVE_PAM_MISC)
+ list(APPEND PAM_LIBRARIES pam_misc)
+endif (HAVE_PAM_MISC)
set(PWRAP_PRIVATE_LIBRARIES
${LIB_INSTALL_DIR}/pam_wrapper)
diff --git a/src/modules/pam_get_items.c b/src/modules/pam_get_items.c
index ec9f70f..bd1da0a 100644
--- a/src/modules/pam_get_items.c
+++ b/src/modules/pam_get_items.c
@@ -15,13 +15,20 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <security/pam_modules.h>
+#ifdef HAVE_SECURITY_PAM_APPL_H
#include <security/pam_appl.h>
+#endif
+#ifdef HAVE_SECURITY_PAM_MODULES_H
+#include <security/pam_modules.h>
+#endif
+
+#include "pwrap_compat.h"
static const char *str_opt(const int opt)
{
@@ -42,10 +49,14 @@ static const char *str_opt(const int opt)
return "PAM_AUTHTOK";
case PAM_OLDAUTHTOK:
return "PAM_OLDAUTHTOK";
+#ifdef PAM_XDISPLAY
case PAM_XDISPLAY:
return "PAM_XDISPLAY";
+#endif
+#ifdef PAM_AUTHTOK_TYPE
case PAM_AUTHTOK_TYPE:
return "PAM_AUTHTOK_TYPE";
+#endif
}
return NULL; /* Unsupported */
@@ -105,8 +116,12 @@ static int pam_putitem(pam_handle_t *pamh)
putenv_item(pamh, PAM_RHOST);
putenv_item(pamh, PAM_AUTHTOK);
putenv_item(pamh, PAM_OLDAUTHTOK);
+#ifdef PAM_XDISPLAY
putenv_item(pamh, PAM_XDISPLAY);
+#endif
+#ifdef PAM_AUTHTOK_TYPE
putenv_item(pamh, PAM_AUTHTOK_TYPE);
+#endif
return PAM_SUCCESS;
}
diff --git a/src/modules/pam_matrix.c b/src/modules/pam_matrix.c
index c84bca0..21dd551 100644
--- a/src/modules/pam_matrix.c
+++ b/src/modules/pam_matrix.c
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2015 Andreas Schneider <asn@samba.org>
+ * Copyright (c) 2015 Jakub Hrozek <jakub.hrozek@posteo.se>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
#include <sys/param.h>
#include <pwd.h>
@@ -9,9 +29,17 @@
#include <errno.h>
#include <time.h>
-#include <security/pam_modules.h>
+#ifdef HAVE_SECURITY_PAM_APPL_H
#include <security/pam_appl.h>
+#endif
+#ifdef HAVE_SECURITY_PAM_MODULES_H
+#include <security/pam_modules.h>
+#endif
+#ifdef HAVE_SECURITY_PAM_EXT_H
#include <security/pam_ext.h>
+#endif
+
+#include "pwrap_compat.h"
#define HOME_VAR "HOMEDIR"
#define HOME_VAR_SZ sizeof(HOME_VAR)-1
diff --git a/src/modules/pam_set_items.c b/src/modules/pam_set_items.c
index 0fccf4c..ae6ef9f 100644
--- a/src/modules/pam_set_items.c
+++ b/src/modules/pam_set_items.c
@@ -15,13 +15,20 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <security/pam_modules.h>
+#ifdef HAVE_SECURITY_PAM_APPL_H
#include <security/pam_appl.h>
+#endif
+#ifdef HAVE_SECURITY_PAM_MODULES_H
+#include <security/pam_modules.h>
+#endif
+
+#include "config.h"
#define ITEM_FILE_KEY "item_file="
@@ -34,8 +41,12 @@ static const char *envs[] = {
"PAM_RHOST",
"PAM_AUTHTOK",
"PAM_OLDAUTHTOK",
+#ifdef PAM_XDISPLAY
"PAM_XDISPLAY",
+#endif
+#ifdef PAM_AUTHTOK_TYPE
"PAM_AUTHTOK_TYPE",
+#endif
NULL
};
@@ -48,8 +59,12 @@ static const int items[] = {
PAM_RHOST,
PAM_AUTHTOK,
PAM_OLDAUTHTOK,
+#ifdef PAM_XDISPLAY
PAM_XDISPLAY,
+#endif
+#ifdef PAM_AUTHTOK_TYPE
PAM_AUTHTOK_TYPE,
+#endif
};
static void pam_setitem_env(pam_handle_t *pamh)
diff --git a/src/pam_wrapper.c b/src/pam_wrapper.c
index 59119ab..50d6f81 100644
--- a/src/pam_wrapper.c
+++ b/src/pam_wrapper.c
@@ -38,8 +38,14 @@
#ifdef HAVE_SECURITY_PAM_APPL_H
#include <security/pam_appl.h>
#endif
+#ifdef HAVE_SECURITY_PAM_MODULES_H
#include <security/pam_modules.h>
+#endif
+#ifdef HAVE_SECURITY_PAM_EXT_H
#include <security/pam_ext.h>
+#endif
+
+#include "pwrap_compat.h"
#ifdef HAVE_GCC_THREAD_LOCAL_STORAGE
# define PWRAP_THREAD __thread
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index d98e1be..e501267 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -24,9 +24,10 @@ else ()
set(TEST_ENVIRONMENT LD_PRELOAD=${PAM_WRAPPER_LOCATION};PAM_WRAPPER=1;PAM_WRAPPER_CONFDIR=${CMAKE_CURRENT_BINARY_DIR}/services)
endif ()
-set(PAM_LIBRARIES
- pam
- pam_misc)
+set(PAM_LIBRARIES pam)
+if (HAVE_PAM_MISC)
+ list(APPEND PAM_LIBRARIES pam_misc)
+endif (HAVE_PAM_MISC)
set(TEST_LIBRARIES
pamtest
diff --git a/tests/test_pam_wrapper.c b/tests/test_pam_wrapper.c
index 1c78476..129ea84 100644
--- a/tests/test_pam_wrapper.c
+++ b/tests/test_pam_wrapper.c
@@ -1,3 +1,21 @@
+/*
+ * Copyright (c) 2015 Andreas Schneider <asn@samba.org>
+ * Copyright (c) 2015 Jakub Hrozek <jakub.hrozek@posteo.se>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#include "config.h"
#include <stdarg.h>
@@ -14,9 +32,18 @@
#include <syslog.h>
#include <sys/stat.h>
#include <sys/types.h>
+
+#ifdef HAVE_SECURITY_PAM_APPL_H
#include <security/pam_appl.h>
+#endif
+#ifdef HAVE_SECURITY_PAM_MODULES_H
+#include <security/pam_modules.h>
+#endif
+#ifdef HAVE_SECURITY_PAM_EXT_H
#include <security/pam_ext.h>
+#endif
+#include "pwrap_compat.h"
#include "libpamtest.h"
#ifndef ZERO_STRUCT
@@ -731,8 +758,12 @@ static void test_get_set(void **state)
test_setenv("PAM_RHOST");
test_setenv("PAM_AUTHTOK");
test_setenv("PAM_OLDAUTHTOK");
+#ifdef PAM_XDISPLAY
test_setenv("PAM_XDISPLAY");
+#endif
+#ifdef PAM_AUTHTOK_TYPE
test_setenv("PAM_AUTHTOK_TYPE");
+#endif
perr = pamtest("pwrap_get_set", "trinity", NULL, tests);
assert_int_equal(perr, PAMTEST_ERR_OK);
@@ -753,8 +784,12 @@ static void test_get_set(void **state)
test_getenv(tests[1].case_out.envlist, "PAM_RHOST");
test_getenv(tests[1].case_out.envlist, "PAM_AUTHTOK");
test_getenv(tests[1].case_out.envlist, "PAM_OLDAUTHTOK");
+#ifdef PAM_XDISPLAY
test_getenv(tests[1].case_out.envlist, "PAM_XDISPLAY");
+#endif
+#ifdef PAM_AUTHTOK_TYPE
test_getenv(tests[1].case_out.envlist, "PAM_AUTHTOK_TYPE");
+#endif
pamtest_free_env(tests[1].case_out.envlist);
}