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