Hi Krzysztof,

On Wed, Mar 03, 2010 at 12:29:01AM +0100, Krzysztof Ol??dzki wrote:
> First, sorry for the problem I have made. :(

hey please don't be sorry, here we say that we don't make
omelettes without breaking eggs :-)

> Accoriding to crypt(3) from man-pages-3.21 it is required to define 
> _XOPEN_SOURCE:

I've seen this man page but it does not reflect anything I've seen
on any other system, nor even what is required on my machines !
...
Oh sorry, I did not build the test program with -Wall. Shame on me!
Yes I now do see the same one on linux with glibc 2.7 :-(

(...)
> 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:

You rock :-)

Here on linux glibc-2.7, it does not cause any warning (not either
for strdup which you initially had). Solaris 8 builds without a
warning too.

Let's wait for Ross to test on FreeBSD and if that's OK, I apply
the patch and release 1.4.1.

> 
> --- 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)".

OK I'm testing it now then and will keep you informed.

Thanks,
Willy


Reply via email to