On 2010-03-02 23:43, Willy Tarreau wrote:
Hi Holger,
Hi Willy,
Hi Holer,
I could get the same errors on my ultra5 under solaris 8
which correctly builds 1.3. I finally tracked that down to
the #define XOPEN_SOURCE 500 in auth.c. If I remove it,
everything builds as before.
Krzysztof, you told me you had to add it otherwise you got a
warning on your platform with crypt() not being defined. Could
you check if you manage to get rid of the warning by adding a
few common #includes ? The only case I had to add such #defines
was when porting code from very old unixes to linux, but generally
those defines are needed as last resort portability tricks. And
since the crypt() function has been there for decades, I find it
strange that we absolutely need such a define.
First, sorry for the problem I have made. :(
Accoriding to crypt(3) from man-pages-3.21 it is required to define
_XOPEN_SOURCE:
(...)
SYNOPSIS
#define _XOPEN_SOURCE
#include <unistd.h>
char *crypt(const char *key, const char *salt);
(...)
This short program proves the man page is right:
--- ctest.c begin ---
#include <unistd.h>
int main() {
char *c;
crypt(c, c);
return 0;
}
--- ctest.c end ---
$ cc ctest.c -o ctest -Wall -lcrypt ; echo $?
ctest.c: In function 'main':
ctest.c:6: warning: implicit declaration of function 'crypt'
0
$ cc ctest.c -o ctest -Wall -lcrypt -D_XOPEN_SOURCE ; echo $?
0
It behaves exactly in the same way on glibc-2.7, 2.8 and 2.9 on both
i386 and x86-64.
In /usr/include/unistd.h I found:
#ifdef __USE_XOPEN
/* Encrypt at most 8 characters from KEY using salt to perturb DES. */
extern char *crypt (__const char *__key, __const char *__salt)
__THROW __nonnull ((1, 2));
(...)
__USE_XOPEN is defined in features.h:
#ifdef _XOPEN_SOURCE
# define __USE_XOPEN 1
(...)
However, instead of using _XOPEN_SOURCE we may use something less
invasive (I hope), like for example _GNU_SOURCE.
Could you please check, if it helps? Also, there is no point in
including unistd.c and adding one of the above defines for crypt() if
CONFIG_HAP_CRYPT is not defined. So, the final fix may look like this:
--- cut here ---
index 93af8d6..b00727f 100644
--- a/src/auth.c
+++ b/src/auth.c
@@ -10,12 +10,14 @@
*
*/
-#define _XOPEN_SOURCE 500
+#ifdef CONFIG_HAP_CRYPT
+#define _GNU_SOURCE
+#include <unistd.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <common/config.h>
--- cut here ---
Finally, encryption was only tested on Linux and FreeBSD so it could be
nice to verify if it works on Solaris in the same way (with -lcrypt) and
to add USE_LIBCRYPT for "ifeq ($(TARGET),solaris)".
Best regards,
Krzysztof Olędzki