nwrap: Add NWRAP_REINIT_ALL to initialize mutexes
[nss_wrapper.git] / ConfigureChecks.cmake
index ef689b877f8d21216a8c5bcff3283bb07915ef95..5bd69dba38ff78ae0e4f171e886c2239e4aa62ac 100644 (file)
@@ -6,9 +6,10 @@ include(CheckTypeSize)
 include(CheckStructHasMember)
 include(CheckPrototypeDefinition)
 include(TestBigEndian)
+include(CheckCSourceRuns)
 
-set(PACKAGE ${APPLICATION_NAME})
-set(VERSION ${APPLICATION_VERSION})
+set(PACKAGE ${PROJECT_NAME})
+set(VERSION ${PROJECT_VERSION})
 set(DATADIR ${DATA_INSTALL_DIR})
 set(LIBDIR ${LIB_INSTALL_DIR})
 set(PLUGINDIR "${PLUGIN_INSTALL_DIR}-${LIBRARY_SOVERSION}")
@@ -49,6 +50,7 @@ endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
 # HEADERS
 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
 check_include_file(pwd.h HAVE_PWD_H)
+check_include_file(shadow.h HAVE_SHADOW_H)
 check_include_file(grp.h HAVE_GRP_H)
 check_include_file(nss.h HAVE_NSS_H)
 check_include_file(nss_common.h HAVE_NSS_COMMON_H)
@@ -62,6 +64,9 @@ check_function_exists(getpwnam_r HAVE_GETPWNAM_R)
 check_function_exists(getpwuid_r HAVE_GETPWUID_R)
 check_function_exists(getpwent_r HAVE_GETPWENT_R)
 
+check_function_exists(setspent HAVE_SETSPENT)
+check_function_exists(getspnam HAVE_GETSPNAM)
+
 check_function_exists(getgrnam_r HAVE_GETGRNAM_R)
 check_function_exists(getgrgid_r HAVE_GETGRGID_R)
 check_function_exists(getgrent_r HAVE_GETGRENT_R)
@@ -71,6 +76,12 @@ check_function_exists(getgrouplist HAVE_GETGROUPLIST)
 check_function_exists(gethostbyaddr_r HAVE_GETHOSTBYADDR_R)
 check_function_exists(gethostbyname_r HAVE_GETHOSTBYNAME_R)
 
+check_function_exists(gethostbyname2 HAVE_GETHOSTBYNAME2)
+check_function_exists(gethostbyname2_r HAVE_GETHOSTBYNAME2_R)
+
+check_function_exists(getprogname HAVE_GETPROGNAME)
+check_function_exists(getexecname HAVE_GETEXECNAME)
+
 if (WIN32)
     check_function_exists(_vsnprintf_s HAVE__VSNPRINTF_S)
     check_function_exists(_vsnprintf HAVE__VSNPRINTF)
@@ -83,13 +94,13 @@ if (UNIX)
         # libsocket (Solaris)
         check_library_exists(socket getaddrinfo "" HAVE_LIBSOCKET)
         if (HAVE_LIBSOCKET)
-          set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} socket)
+            list(APPEND _REQUIRED_LIBRARIES socket)
         endif (HAVE_LIBSOCKET)
 
         # libnsl/inet_pton (Solaris)
         check_library_exists(nsl inet_pton "" HAVE_LIBNSL)
         if (HAVE_LIBNSL)
-            set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} nsl)
+            list(APPEND _REQUIRED_LIBRARIES nsl)
         endif (HAVE_LIBNSL)
     endif (NOT LINUX)
 
@@ -177,8 +188,17 @@ check_prototype_definition(getnameinfo
     "unistd.h;netdb.h"
     HAVE_LINUX_GETNAMEINFO)
 
+check_prototype_definition(getnameinfo
+    "int getnameinfo (const struct sockaddr *sa, socklen_t salen, char *host, socklen_t __hostlen, char *serv, socklen_t servlen, unsigned int flags)"
+    "-1"
+    "unistd.h;netdb.h"
+    HAVE_LINUX_GETNAMEINFO_UNSIGNED)
+
 # STRUCT MEMBERS
 check_struct_has_member("struct sockaddr" sa_len "sys/socket.h netinet/in.h" HAVE_STRUCT_SOCKADDR_SA_LEN)
+check_struct_has_member("struct passwd" pw_class "pwd.h" HAVE_STRUCT_PASSWD_PW_CLASS)
+check_struct_has_member("struct passwd" pw_change "pwd.h" HAVE_STRUCT_PASSWD_PW_CHANGE)
+check_struct_has_member("struct passwd" pw_expire "pwd.h" HAVE_STRUCT_PASSWD_PW_EXPIRE)
 
 # IPV6
 check_c_source_compiles("
@@ -212,15 +232,140 @@ int main(void) {
     return 0;
 }" HAVE_IPV6)
 
-check_library_exists(dl dlopen "" HAVE_LIBDL)
-if (HAVE_LIBDL)
-    find_library(DLFCN_LIBRARY dl)
-    set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${DLFCN_LIBRARY})
-endif (HAVE_LIBDL)
+check_c_source_compiles("
+void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
+
+int main(void) {
+    return 0;
+}" HAVE_ATTRIBUTE_PRINTF_FORMAT)
+
+check_c_source_compiles("
+void test_constructor_attribute(void) __attribute__ ((constructor));
+
+void test_constructor_attribute(void)
+{
+     return;
+}
+
+int main(void) {
+     return 0;
+}" HAVE_CONSTRUCTOR_ATTRIBUTE)
+
+check_c_source_compiles("
+void test_destructor_attribute(void) __attribute__ ((destructor));
+
+void test_destructor_attribute(void)
+{
+    return;
+}
+
+int main(void) {
+    return 0;
+}" HAVE_DESTRUCTOR_ATTRIBUTE)
+
+check_c_source_compiles("
+#pragma init (test_constructor)
+void test_constructor(void);
+
+void test_constructor(void)
+{
+     return;
+}
+
+int main(void) {
+     return 0;
+}" HAVE_PRAGMA_INIT)
+
+check_c_source_compiles("
+#pragma fini (test_destructor)
+void test_destructor(void);
+
+void test_destructor(void)
+{
+    return;
+}
+
+int main(void) {
+    return 0;
+}" HAVE_PRAGMA_FINI)
+
+find_library(DLFCN_LIBRARY dl)
+if (DLFCN_LIBRARY)
+    list(APPEND _REQUIRED_LIBRARIES ${DLFCN_LIBRARY})
+else()
+    check_function_exists(dlopen HAVE_DLOPEN)
+    if (NOT HAVE_DLOPEN)
+        message(FATAL_ERROR "FATAL: No dlopen() function detected")
+    endif()
+endif()
 
 # ENDIAN
 if (NOT WIN32)
     test_big_endian(WORDS_BIGENDIAN)
 endif (NOT WIN32)
 
-set(NWRAP_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "nss_wrapper required system libraries")
+if (NOT CMAKE_CROSSCOMPILING)
+    # check whether getaddrinfo() returns "node" in "ai_canonname" for IP-addresses
+    check_c_source_runs("#include <stddef.h>
+    #include <string.h>
+    #include <sys/types.h>
+    #include <sys/socket.h>
+    #include <netdb.h>
+
+    int main(void) {
+        struct addrinfo hints;
+        struct addrinfo *res = NULL;
+
+        memset(&hints, 0, sizeof(struct addrinfo));
+        hints.ai_family = AF_INET;
+        hints.ai_socktype = SOCK_STREAM;
+        hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
+
+        if (getaddrinfo(\"0.0.0.0\", \"389\", &hints, &res) != 0) {
+            return 2;
+        }
+
+        if (res == NULL) {
+            return 3;
+        }
+
+        return strncmp(res->ai_canonname, \"0.0.0.0\", sizeof(\"0.0.0.0\")) != 0;
+    }" HAVE_GETADDRINFO_SETS_CANONNAME_FOR_IPADDRESSES)
+
+    # Check whether getaddrinfo() returns EAI_SERVICE when the requested
+    # service is not available for the requested socket type.
+    check_c_source_runs("#include <stddef.h>
+    #include <string.h>
+    #include <sys/types.h>
+    #include <sys/socket.h>
+    #include <netdb.h>
+
+    int main(void) {
+        struct addrinfo hints;
+        struct addrinfo *res = NULL;
+        int rc;
+
+        memset(&hints, 0, sizeof(struct addrinfo));
+        hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
+        hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
+        hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV;    /* For wildcard IP address */
+        hints.ai_protocol = 0;          /* Any protocol */
+        hints.ai_canonname = NULL;
+
+        rc = getaddrinfo(NULL, \"echo\", &hints, &res);
+        return rc != EAI_SERVICE;
+    }" HAVE_GETADDRINFO_USES_EAI_SERVICE)
+
+    # Check for non-NULL gethostent()
+    check_c_source_runs("#include <stddef.h>
+    #include <netdb.h>
+    int main(void) {
+        struct hostent *hostent = NULL;
+        sethostent(0);
+        hostent = gethostent();
+        endhostent();
+        return hostent == NULL;
+    }" HAVE_NONNULL_GETHOSTENT)
+endif (NOT CMAKE_CROSSCOMPILING)
+
+set(NWRAP_REQUIRED_LIBRARIES ${_REQUIRED_LIBRARIES} CACHE INTERNAL "nss_wrapper required system libraries")