Skip to content

Commit

Permalink
[#9,#14,#17,irods/irods#7265] Minor reorganization + CMake TLC
Browse files Browse the repository at this point in the history
- removed unused `main.cpp`
- reorganized project
- created object library target for `auth_check_wrapper.cpp`
- created interface library target for `ipam_client.hpp`
- quoted paths in cmake
- Removed unneeded `CMAKE_SHARED_LINKER_FLAGS_INIT` and `CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT`
- Added missing `CMAKE_EXE_LINKER_FLAGS_INIT` and `CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT`
- Swapped quotes to angle brackets on irods includes
- Removed references to nonexistent include directory from cmake
- Removed unneeded `pam_conversation.hpp` include from `handshake_session.cpp`
- Bumped irods version and removed exact requirement
- Updated `CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION`
- Split into server and client packages (server package depends on client package)
- Replaced PAM `find_library` logic with a new find module
- Switched to `find_package` for fmt and spdlog

Co-authored-by: ll4strw <l.lenoci@science.leidenuniv.nl>
  • Loading branch information
2 people authored and alanking committed May 24, 2024
1 parent c478407 commit 0dc86eb
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 178 deletions.
189 changes: 45 additions & 144 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,194 +1,95 @@
cmake_minimum_required(VERSION 3.7.0 FATAL_ERROR)

find_package(IRODS 4.3.1 EXACT REQUIRED)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")

set(IRODS_MINIMUM_VERSION "4.3.1")
find_package(IRODS "${IRODS_MINIMUM_VERSION}" REQUIRED)
set(IRODS_PLUGIN_REVISION "0")
set(IRODS_PLUGIN_VERSION "${IRODS_VERSION}.${IRODS_PLUGIN_REVISION}")
set(IRODS_PLUGIN_VERSION "${IRODS_MINIMUM_VERSION}.${IRODS_PLUGIN_REVISION}")

set(IRODS_PACKAGE_REVISION "0")

include(IrodsCXXCompiler)
set(CMAKE_CXX_STANDARD ${IRODS_CXX_STANDARD})
set(CMAKE_EXE_LINKER_FLAGS_INIT "-rdynamic -Wl,--export-dynamic -Wl,--enable-new-dtags -Wl,--as-needed")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-Wl,--enable-new-dtags -Wl,--as-needed -Wl,-z,defs")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-Wl,--enable-new-dtags -Wl,--as-needed -Wl,-z,defs")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "-Wl,--gc-sections -Wl,-z,combreloc")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT "-Wl,--gc-sections -Wl,-z,combreloc")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT "-Wl,--gc-sections -Wl,-z,combreloc")
include(IrodsRunpathDefaults)

project(irods_auth_plugin_pam_interactive
VERSION "${IRODS_PLUGIN_VERSION}"
LANGUAGES CXX
VERSION "${IRODS_PLUGIN_VERSION}"
LANGUAGES CXX
)

include(${IRODS_TARGETS_PATH})
set(plugin_target_part "irods_auth_plugin-pam_interactive")
string(REPLACE "_" "-" project_component_part "${plugin_target_part}")

include("${IRODS_TARGETS_PATH}")

include(GNUInstallDirs)
include(UseLibCXX)

find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED COMPONENTS Crypto SSL)
find_package(nlohmann_json "3.6.1" REQUIRED)
find_package(fmt "8.1.1"
HINTS "${IRODS_EXTERNALS_FULLPATH_FMT}")
find_package(spdlog "1.9.2"
HINTS "${IRODS_EXTERNALS_FULLPATH_SPDLOG}")
find_package(PAM REQUIRED)

# pam interactive
if (NOT PAM_LIBRARY)
find_library(PAM_LIBRARY pam)
if (PAM_LIBRARY)
message(STATUS "Found pam: ${PAM_LIBRARY}")
else()
message(FATAL_ERROR "pam library not found")
endif()
endif()

# Testing executable
add_executable(
pam_handshake_auth_check
"${CMAKE_CURRENT_SOURCE_DIR}/src/auth_check_wrapper.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/auth_check_main.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/pam_conversation.cpp"
)
target_link_libraries(
pam_handshake_auth_check
PRIVATE
"${PAM_LIBRARY}"
)
install(
TARGETS
pam_handshake_auth_check
RUNTIME
DESTINATION "${IRODS_PLUGINS_DIRECTORY}/auth"
)

set(plugin_target_part "irods_auth_plugin-pam_interactive")

# Client-side plugin
add_library(
"${plugin_target_part}_client"
MODULE
"${CMAKE_CURRENT_SOURCE_DIR}/src/pam_interactive.cpp"
)
target_link_libraries(
"${plugin_target_part}_client"
PRIVATE
irods_common
irods_plugin_dependencies
irods_client
"${IRODS_EXTERNALS_FULLPATH_BOOST}/lib/libboost_filesystem.so"
"${IRODS_EXTERNALS_FULLPATH_BOOST}/lib/libboost_system.so"
"${IRODS_EXTERNALS_FULLPATH_BOOST}/lib/libboost_chrono.so"
"${IRODS_EXTERNALS_FULLPATH_FMT}/lib/libfmt.so"
nlohmann_json::nlohmann_json
OpenSSL::Crypto
${CMAKE_DL_LIBS}
)
target_include_directories(
"${plugin_target_part}_client"
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/server/api/include>"
"${IRODS_EXTERNALS_FULLPATH_BOOST}/include"
"${IRODS_EXTERNALS_FULLPATH_FMT}/include"
"${IRODS_EXTERNALS_FULLPATH_SPDLOG}/include"
)
target_compile_definitions(
"${plugin_target_part}_client"
PRIVATE
${IRODS_COMPILE_DEFINITIONS_PRIVATE}
)
install(
TARGETS
"${plugin_target_part}_client"
LIBRARY
DESTINATION "${IRODS_PLUGINS_DIRECTORY}/auth"
)

# Server-side plugin
add_library(
"${plugin_target_part}_server"
MODULE
"${CMAKE_CURRENT_SOURCE_DIR}/src/pam_interactive.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/handshake_session.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/auth_check_wrapper.cpp"
)
target_link_libraries(
"${plugin_target_part}_server"
PRIVATE
irods_common
irods_plugin_dependencies
irods_server
"${IRODS_EXTERNALS_FULLPATH_BOOST}/lib/libboost_filesystem.so"
"${IRODS_EXTERNALS_FULLPATH_BOOST}/lib/libboost_system.so"
"${IRODS_EXTERNALS_FULLPATH_BOOST}/lib/libboost_chrono.so"
"${IRODS_EXTERNALS_FULLPATH_FMT}/lib/libfmt.so"
nlohmann_json::nlohmann_json
OpenSSL::Crypto
${CMAKE_DL_LIBS}
)
target_include_directories(
"${plugin_target_part}_server"
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/server/api/include>"
"${IRODS_EXTERNALS_FULLPATH_BOOST}/include"
"${IRODS_EXTERNALS_FULLPATH_FMT}/include"
"${IRODS_EXTERNALS_FULLPATH_SPDLOG}/include"
)
target_compile_definitions(
"${plugin_target_part}_server"
PRIVATE
${IRODS_COMPILE_DEFINITIONS_PRIVATE}
RODS_SERVER
ENABLE_RE
IRODS_ENABLE_SYSLOG
)
install(
TARGETS
"${plugin_target_part}_server"
LIBRARY
DESTINATION "${IRODS_PLUGINS_DIRECTORY}/auth"
COMPONENT ${IRODS_PACKAGE_COMPONENT_RUNTIME_NAME}
)
add_subdirectory(common)
add_subdirectory(auth_check_wrapper)
add_subdirectory(pam_handshake_auth_check)
add_subdirectory(plugin)

set(PLUGIN_PACKAGE_NAME irods-auth-plugin-pam-interactive)
set(PLUGIN_PACKAGE_NAME "irods-auth-plugin-pam-interactive")

include(IrodsCPackCommon)

list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${IRODS_HOME_DIRECTORY}")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${IRODS_HOME_DIRECTORY}/scripts")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${IRODS_HOME_DIRECTORY}/scripts/irods")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${IRODS_HOME_DIRECTORY}/scripts/irods/test")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${IRODS_PLUGINS_DIRECTORY}")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${IRODS_PLUGINS_DIRECTORY}/auth")

set(CPACK_PACKAGE_VERSION ${IRODS_PLUGIN_VERSION})
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_COMPONENTS_GROUPING IGNORE)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The integrated Rule-Oriented Data System")

set(CPACK_DEB_COMPONENT_INSTALL OFF)
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OFF)
set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION ON)
#set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/packaging/postinst;")
set(CPACK_DEBIAN_PACKAGE_BREAKS ${PLUGIN_PACKAGE_NAME})
set(CPACK_DEBIAN_PACKAGE_REPLACES ${PLUGIN_PACKAGE_NAME})
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)

set(CPACK_RPM_COMPONENT_INSTALL OFF)
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_RPM_PACKAGE_LICENSE "BSD-3-Clause")
set(CPACK_RPM_PACKAGE_AUTOREQ 0)
set(CPACK_RPM_PACKAGE_AUTOPROV 0)
set(CPACK_RPM_PACKAGE_OBSOLETES ${PLUGIN_PACKAGE_NAME})
#set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_SOURCE_DIR}/packaging/postinst")
set(CPACK_RPM_FILE_NAME RPM-DEFAULT)

set(CPACK_ARCHIVE_COMPONENT_INSTALL OFF)
string(TOUPPER "${project_component_part}-client" irods_plugin_package_client_component)
string(TOUPPER "${project_component_part}-server" irods_plugin_package_server_component)

set(CPACK_DEBIAN_${irods_plugin_package_client_component}_PACKAGE_NAME "${PLUGIN_PACKAGE_NAME}-client")
set(CPACK_DEBIAN_${irods_plugin_package_client_component}_PACKAGE_DEPENDS "irods-runtime (= ${IRODS_VERSION}), libc6")
set(CPACK_DEBIAN_${irods_plugin_package_client_component}_PACKAGE_BREAKS "${PLUGIN_PACKAGE_NAME} (<< 4.90.0.0-1~), irods-auth-interactive-pam (<< 4.90.0.0-1~)")
set(CPACK_DEBIAN_${irods_plugin_package_client_component}_PACKAGE_REPLACES "${PLUGIN_PACKAGE_NAME} (<< 4.90.0.0-1~), irods-auth-interactive-pam (<< 4.90.0.0-1~)")

set(CPACK_RPM_${irods_plugin_package_client_component}_PACKAGE_NAME "${PLUGIN_PACKAGE_NAME}-client")
set(CPACK_RPM_${irods_plugin_package_client_component}_PACKAGE_REQUIRES "irods-runtime = ${IRODS_VERSION}")

set(CPACK_DEBIAN_PACKAGE_NAME ${PLUGIN_PACKAGE_NAME})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${IRODS_PACKAGE_DEPENDENCIES_STRING}, irods-server (= ${IRODS_VERSION}), irods-runtime (= ${IRODS_VERSION}), libc6, libpam0g")
set(CPACK_DEBIAN_${irods_plugin_package_server_component}_PACKAGE_NAME "${PLUGIN_PACKAGE_NAME}-server")
set(CPACK_DEBIAN_${irods_plugin_package_server_component}_PACKAGE_DEPENDS "irods-server (= ${IRODS_VERSION}), ${CPACK_DEBIAN_${irods_plugin_package_client_component}_PACKAGE_NAME} (= ${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}), libpam0g")
set(CPACK_DEBIAN_${irods_plugin_package_server_component}_PACKAGE_BREAKS "${PLUGIN_PACKAGE_NAME} (<< 4.90.0.0-1~), irods-auth-interactive-pam (<< 4.90.0.0-1~)")
set(CPACK_DEBIAN_${irods_plugin_package_server_component}_PACKAGE_REPLACES "${PLUGIN_PACKAGE_NAME} (<< 4.90.0.0-1~), irods-auth-interactive-pam (<< 4.90.0.0-1~)")

set(CPACK_RPM_PACKAGE_NAME ${PLUGIN_PACKAGE_NAME})
set(CPACK_RPM_PACKAGE_REQUIRES "${IRODS_PACKAGE_DEPENDENCIES_STRING}, irods-server = ${IRODS_VERSION}, irods-runtime = ${IRODS_VERSION}, pam")
set(CPACK_RPM_${irods_plugin_package_server_component}_PACKAGE_NAME "${PLUGIN_PACKAGE_NAME}-server")
set(CPACK_RPM_${irods_plugin_package_server_component}_PACKAGE_REQUIRES "irods-server = ${IRODS_VERSION}, ${CPACK_RPM_${irods_plugin_package_client_component}_PACKAGE_NAME} = ${CPACK_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}, pam")

if (NOT CPACK_GENERATOR)
set(CPACK_GENERATOR ${IRODS_CPACK_GENERATOR} CACHE STRING "CPack generator to use, e.g. {DEB, RPM, TGZ}." FORCE)
message(STATUS "Setting unspecified CPACK_GENERATOR to ${CPACK_GENERATOR}. This is the correct setting for normal builds.")
set(CPACK_GENERATOR ${IRODS_CPACK_GENERATOR} CACHE STRING "CPack generator to use, e.g. {DEB, RPM, TGZ}." FORCE)
message(STATUS "Setting unspecified CPACK_GENERATOR to ${CPACK_GENERATOR}. This is the correct setting for normal builds.")
endif()

include(CPack)
19 changes: 19 additions & 0 deletions auth_check_wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
add_library(
irods_pam_auth_check_wrapper_obj
OBJECT
"${CMAKE_CURRENT_SOURCE_DIR}/src/auth_check_wrapper.cpp"
)
target_link_libraries(
irods_pam_auth_check_wrapper_obj
PUBLIC
irods_pam_interactive_common
PAM::pam
)
target_include_directories(
irods_pam_auth_check_wrapper_obj
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
)

set_target_properties(irods_pam_auth_check_wrapper_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
set_target_properties(irods_pam_auth_check_wrapper_obj PROPERTIES EXCLUDE_FROM_ALL TRUE)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "ipam_client.hpp"
#include "irods/private/pam/ipam_client.hpp"
#include <string>

namespace PamHandshake
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "auth_check_wrapper.hpp"
#include "pam_auth_check_exception.hpp"
#include "irods/private/pam/auth_check_wrapper.hpp"
#include "irods/private/pam/pam_auth_check_exception.hpp"
#include <cstdint>
#include <cstring>
#include <stdio.h>
Expand Down
64 changes: 64 additions & 0 deletions cmake/Modules/FindPAM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#[=======================================================================[.rst:
FindPAM
-----------

Finds PAM.

IMPORTED Targets
^^^^^^^^^^^^^^^^

The following :prop_tgt:`IMPORTED` targets may be defined:

``PAM::pam``
Main PAM library.

Result variables
^^^^^^^^^^^^^^^^

This module will set the following variables in your project:

``PAM_FOUND``
true if PAM headers and library were found
``PAM_LIBRARY``
PAM library to be linked
``PAM_INCLUDE_DIR``
the directory containing PAM headers

TODO (irods/irods#6247)
^^^^^^^^^^^^^^^^^^^^^^^

* pam_misc
* pamc
* Components
* Version matching
* pkgconfig?

#]=======================================================================]

cmake_policy(PUSH)
cmake_policy(SET CMP0054 NEW) # Only interpret if() arguments as variables or keywords when unquoted

find_path(
PAM_INCLUDE_DIR
NAMES "security/pam_appl.h" "pam/pam_appl.h"
)
find_library(
PAM_LIBRARY
NAMES "pam"
)

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
PAM
REQUIRED_VARS PAM_INCLUDE_DIR PAM_LIBRARY
)

if (PAM_FOUND)
if (NOT TARGET PAM::pam)
add_library(PAM::pam UNKNOWN IMPORTED)
set_target_properties(PAM::pam PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${PAM_INCLUDE_DIR}")
set_target_properties(PAM::pam PROPERTIES IMPORTED_LOCATION "${PAM_LIBRARY}")
endif()
endif()

cmake_policy(POP)
9 changes: 9 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_library(
irods_pam_interactive_common
INTERFACE
)
target_include_directories(
irods_pam_interactive_common
INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
)
File renamed without changes.
30 changes: 30 additions & 0 deletions pam_handshake_auth_check/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
include(ObjectTargetHelpers)

add_executable(
pam_handshake_auth_check
"${CMAKE_CURRENT_SOURCE_DIR}/src/auth_check_main.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/pam_conversation.cpp"
)
target_link_objects(
pam_handshake_auth_check
PRIVATE
irods_pam_auth_check_wrapper_obj
)
target_link_libraries(
pam_handshake_auth_check
PRIVATE
PAM::pam
)
target_include_directories(
pam_handshake_auth_check
PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
)

install(
TARGETS
pam_handshake_auth_check
RUNTIME
DESTINATION "${IRODS_PLUGINS_DIRECTORY}/auth"
COMPONENT "${project_component_part}-server"
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <string>
#include <utility>
#include <security/pam_appl.h>
#include "ipam_client.hpp"
#include "pam_auth_check_exception.hpp"
#include "irods/private/pam/ipam_client.hpp"
#include "irods/private/pam/pam_auth_check_exception.hpp"

namespace PamHandshake
{
Expand Down
Loading

0 comments on commit 0dc86eb

Please sign in to comment.