1# - Try to find the PAM libraries
2# Once done this will define
3#
4#  PAM_FOUND - system has pam
5#  PAM_INCLUDE_DIR - the pam include directory
6#  PAM_LIBRARIES - libpam library
7#
8# SPDX-License-Identifier: BSD-3-Clause
9
10if (PAM_INCLUDE_DIR AND PAM_LIBRARY)
11	# Already in cache, be silent
12	set(PAM_FIND_QUIETLY TRUE)
13endif (PAM_INCLUDE_DIR AND PAM_LIBRARY)
14
15find_path(PAM_INCLUDE_DIR NAMES security/pam_appl.h pam/pam_appl.h)
16find_library(PAM_LIBRARY pam)
17find_library(DL_LIBRARY dl)
18
19if (PAM_INCLUDE_DIR AND PAM_LIBRARY)
20	set(PAM_FOUND TRUE)
21	if (DL_LIBRARY)
22		set(PAM_LIBRARIES ${PAM_LIBRARY} ${DL_LIBRARY})
23	else (DL_LIBRARY)
24		set(PAM_LIBRARIES ${PAM_LIBRARY})
25	endif (DL_LIBRARY)
26
27	if (EXISTS ${PAM_INCLUDE_DIR}/pam/pam_appl.h)
28		# darwin claims to be something special
29		set(HAVE_PAM_PAM_APPL_H 1)
30	endif (EXISTS ${PAM_INCLUDE_DIR}/pam/pam_appl.h)
31
32	if (NOT DEFINED PAM_MESSAGE_CONST)
33		include(CheckCXXSourceCompiles)
34		# XXX does this work with plain c?
35		check_cxx_source_compiles("
36#if ${HAVE_PAM_PAM_APPL_H}+0
37# include <pam/pam_appl.h>
38#else
39# include <security/pam_appl.h>
40#endif
41
42static int PAM_conv(
43	int num_msg,
44	const struct pam_message **msg, /* this is the culprit */
45	struct pam_response **resp,
46	void *ctx)
47{
48	return 0;
49}
50
51int main(void)
52{
53	struct pam_conv PAM_conversation = {
54		&PAM_conv, /* this bombs out if the above does not match */
55		0
56	};
57
58	return 0;
59}
60" PAM_MESSAGE_CONST)
61	endif (NOT DEFINED PAM_MESSAGE_CONST)
62	set(PAM_MESSAGE_CONST ${PAM_MESSAGE_CONST} CACHE BOOL "PAM expects a conversation function with const pam_message")
63
64endif (PAM_INCLUDE_DIR AND PAM_LIBRARY)
65
66if (PAM_FOUND)
67	if (NOT PAM_FIND_QUIETLY)
68		message(STATUS "Found PAM: ${PAM_LIBRARIES}")
69	endif (NOT PAM_FIND_QUIETLY)
70else (PAM_FOUND)
71	if (PAM_FIND_REQUIRED)
72		message(FATAL_ERROR "PAM was not found")
73	endif(PAM_FIND_REQUIRED)
74endif (PAM_FOUND)
75
76mark_as_advanced(PAM_INCLUDE_DIR PAM_LIBRARY DL_LIBRARY PAM_MESSAGE_CONST)
77