From 890a33e41f6ed7e7b56967b31a23731f52094e04 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 4 Mar 2010 19:10:14 +0100 Subject: [PATCH] [BUILD] fix platform-dependant build issues related to crypt() Holger Just and Ross West reported build issues on FreeBSD and Solaris that were initially caused by the definition of _XOPEN_SOURCE at the top of auth.c, which was required on Linux to avoid a build warning. Krzysztof Oledzki found that using _GNU_SOURCE instead also worked on Linux and did not cause any issue on several versions of FreeBSD. Solaris still reported a warning this time, which was fixed by including , which itself is not present on FreeBSD nor on all Linux toolchains. So by adding a new build option (NEED_CRYPT_H), we can get Solaris to get crypt() working and stop complaining at the same time, without impacting other platforms. This fix was tested at least on several linux toolchains (at least uclibc, glibc 2.2.5, 2.3.6 and 2.7), on FreeBSD 4 to 8, Solaris 8 (which needs crypt.h), and AIX 5.3 (without crypt.h). Every time it builds without a warning. --- Makefile | 9 +++++++++ src/auth.c | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 022731d8b..4c1335582 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,8 @@ # USE_TPROXY : enable transparent proxy. Automatic. # USE_LINUX_TPROXY : enable full transparent proxy (need kernel patch). # USE_LINUX_SPLICE : enable kernel 2.6 splicing (broken on old kernels) +# USE_LIBCRYPT : enable crypted passwords using -lcrypt +# USE_CRYPT_H : set it if your system requires including crypt.h # # Options can be forced by specifying "USE_xxx=1" or can be disabled by using # "USE_xxx=" (empty string). @@ -208,6 +210,8 @@ ifeq ($(TARGET),solaris) TARGET_CFLAGS = -fomit-frame-pointer -DFD_SETSIZE=65536 -D_REENTRANT TARGET_LDFLAGS = -lnsl -lsocket USE_TPROXY = implicit + USE_LIBCRYPT = implicit + USE_CRYPT_H = implicit else ifeq ($(TARGET),freebsd) # This is for FreeBSD @@ -336,6 +340,11 @@ BUILD_OPTIONS += $(call ignore_implicit,USE_LIBCRYPT) OPTIONS_LDFLAGS += -lcrypt endif +ifneq ($(USE_CRYPT_H),) +OPTIONS_CFLAGS += -DNEED_CRYPT_H +BUILD_OPTIONS += $(call ignore_implicit,USE_CRYPT_H) +endif + ifneq ($(USE_POLL),) OPTIONS_CFLAGS += -DENABLE_POLL OPTIONS_OBJS += src/ev_poll.o diff --git a/src/auth.c b/src/auth.c index 93af8d68c..8ae485864 100644 --- a/src/auth.c +++ b/src/auth.c @@ -10,7 +10,15 @@ * */ -#define _XOPEN_SOURCE 500 +#ifdef CONFIG_HAP_CRYPT +/* This is to have crypt() defined on Linux */ +#define _GNU_SOURCE + +#ifdef NEED_CRYPT_H +/* some platforms such as Solaris need this */ +#include +#endif +#endif /* CONFIG_HAP_CRYPT */ #include #include