blob: 252b116fd8553421e989f9a2187a015bf8e4abef [file] [log] [blame]
roman41a11e42022-06-22 09:27:08 +02001# - Try to find LibPAM
2# Once done this will define
3#
4# LIBPAM_FOUND - system has LibPAM
5# LIBPAM_INCLUDE_DIRS - the LibPAM include directory
6# LIBPAM_LIBRARIES - link these to use LibPAM
7# LIBPAM_HAVE_CONFDIR - LibPAM version >= 1.4
8#
9# Author Roman Janota <xjanot04@fit.vutbr.cz>
10# Copyright (c) 2022 CESNET, z.s.p.o.
11#
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions
14# are met:
15#
16# 1. Redistributions of source code must retain the copyright
17# notice, this list of conditions and the following disclaimer.
18# 2. Redistributions in binary form must reproduce the copyright
19# notice, this list of conditions and the following disclaimer in the
20# documentation and/or other materials provided with the distribution.
21# 3. The name of the author may not be used to endorse or promote products
22# derived from this software without specific prior written permission.
23#
24# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34#
35
36if(LIBPAM_LIBRARIES AND LIBPAM_INCLUDE_DIRS)
37 # in cache already
38 set(LIBPAM_FOUND TRUE)
39else()
40
41 find_path(LIBPAM_INCLUDE_DIR
42 NAMES
43 security/pam_appl.h
44 security/pam_modules.h
45 PATHS
46 /opt/local/include
47 /sw/include
48 ${CMAKE_INCLUDE_PATH}
49 ${CMAKE_INSTALL_PREFIX}/include
50 )
51
52 find_library(LIBPAM_LIBRARY
53 NAMES
54 pam
55 PATHS
56 /usr/lib
57 /usr/lib64
58 /opt/local/lib
59 /sw/lib
60 ${CMAKE_LIBRARY_PATH}
61 ${CMAKE_INSTALL_PREFIX}/lib
62 )
63
64 if(LIBPAM_INCLUDE_DIR AND LIBPAM_LIBRARY)
65 set(LIBPAM_FOUND TRUE)
66 # there is no reliable way to check the version of PAM, so see if the declaration of a function pam_start_confdir
67 # is in the header file (added in PAM 1.4)
68 file(STRINGS ${LIBPAM_INCLUDE_DIR}/security/pam_appl.h PAM_CONFDIR REGEX "pam_start_confdir")
69 if ("${PAM_CONFDIR}" STREQUAL "")
70 set(LIBPAM_HAVE_CONFDIR FALSE)
71 else()
72 set(LIBPAM_HAVE_CONFDIR TRUE)
73 endif()
74 else()
75 set(LIBPAM_FOUND FALSE)
76 endif()
77
78 set(LIBPAM_INCLUDE_DIRS ${LIBPAM_INCLUDE_DIR})
79 set(LIBPAM_LIBRARIES ${LIBPAM_LIBRARY})
80
81 include(FindPackageHandleStandardArgs)
82 find_package_handle_standard_args(LibPAM DEFAULT_MSG LIBPAM_LIBRARIES LIBPAM_INCLUDE_DIRS)
83
84 # show the LIBPAM_INCLUDE_DIRS and LIBPAM_LIBRARIES variables only in the advanced view
85 mark_as_advanced(LIBPAM_INCLUDE_DIRS LIBPAM_LIBRARIES)
86
87endif()