Need help with autoconf
Hi!
I'm trying to write an autoconf macro to figure out if the function
krb5_free_unparsed_name exists (because it exists in MIT but not Heimdal),
to fix a rather nasty bug in our Kerberos implementation.
However, I'm failing :(
I'm simply using
AC_CHECK_FUNC([krb5_free_unparsed_name])
which works fine on unix, but breaks on win32. Because autoconf tries the
function with no parameters, which doesn't work due to win32 decorations.
The function is declared in krb5.h - is there some way to make autoconf
load that header file and use the declaration from there?
(If I manually set HAVE_KRB5_FREE_UNPARSED_NAME, I can perfectly well *use*
the function as long as I put the correct number of arguments in there)
//Magnus
Magnus Hagander <magnus@hagander.net> writes:
I'm simply using
AC_CHECK_FUNC([krb5_free_unparsed_name])
which works fine on unix, but breaks on win32. Because autoconf tries the
function with no parameters, which doesn't work due to win32 decorations.
Doesn't work why? We have dozens of other functions we check for
without needing any special windoze hacks. Is it a macro?
regards, tom lane
Tom Lane wrote:
Magnus Hagander <magnus@hagander.net> writes:
I'm simply using
AC_CHECK_FUNC([krb5_free_unparsed_name])
which works fine on unix, but breaks on win32. Because autoconf tries the
function with no parameters, which doesn't work due to win32 decorations.Doesn't work why? We have dozens of other functions we check for
without needing any special windoze hacks. Is it a macro?
No, it actually depends on how the library is compiled. Functions can
either be exported decorated or not. This one is exported decorated.
Also, if it just checks for a function with zero arguments, decorated
and non-decorated look the same.
//magnus
Magnus Hagander <magnus@hagander.net> writes:
Tom Lane wrote:
Magnus Hagander <magnus@hagander.net> writes:
I'm simply using
AC_CHECK_FUNC([krb5_free_unparsed_name])
which works fine on unix, but breaks on win32. Because autoconf tries the
function with no parameters, which doesn't work due to win32 decorations.Doesn't work why? We have dozens of other functions we check for
without needing any special windoze hacks. Is it a macro?
No, it actually depends on how the library is compiled. Functions can
either be exported decorated or not. This one is exported decorated.
It's still not apparent to me how this function is different from every
other one we check for; but I'd suggest you write a check that looks
like the ones we use for functions that might be macros, eg sigsetjmp.
regards, tom lane
On Wed, Jul 11, 2007 at 01:41:56PM -0400, Tom Lane wrote:
Magnus Hagander <magnus@hagander.net> writes:
Tom Lane wrote:
Magnus Hagander <magnus@hagander.net> writes:
I'm simply using
AC_CHECK_FUNC([krb5_free_unparsed_name])
which works fine on unix, but breaks on win32. Because autoconf tries the
function with no parameters, which doesn't work due to win32 decorations.Doesn't work why? We have dozens of other functions we check for
without needing any special windoze hacks. Is it a macro?No, it actually depends on how the library is compiled. Functions can
either be exported decorated or not. This one is exported decorated.It's still not apparent to me how this function is different from every
other one we check for; but I'd suggest you write a check that looks
like the ones we use for functions that might be macros, eg sigsetjmp.
Thanks for the pointer. Attached is what I came up with. If someone
autoconfy can sign off on that it seems correct, I'll apply that.
(It passes my tests on both linux and win32 now..)
//Magnus
Attachments:
krb5_free.difftext/plain; charset=us-asciiDownload
Index: configure
===================================================================
RCS file: /cvsroot/pgsql/configure,v
retrieving revision 1.551
diff -c -r1.551 configure
*** configure 10 Jul 2007 16:41:01 -0000 1.551
--- configure 12 Jul 2007 12:18:08 -0000
***************
*** 14398,14403 ****
--- 14398,14461 ----
fi
+
+ # Win32 requires headers to be loaded for __stdcall, so can't use
+ # AC_CHECK_FUNCS here.
+ echo "$as_me:$LINENO: checking for krb5_free_unparsed_name" >&5
+ echo $ECHO_N "checking for krb5_free_unparsed_name... $ECHO_C" >&6
+ cat >conftest.$ac_ext <<_ACEOF
+ /* confdefs.h. */
+ _ACEOF
+ cat confdefs.h >>conftest.$ac_ext
+ cat >>conftest.$ac_ext <<_ACEOF
+ /* end confdefs.h. */
+ #include <krb5.h>
+ int
+ main ()
+ {
+ krb5_free_unparsed_name(NULL,NULL);
+ ;
+ return 0;
+ }
+ _ACEOF
+ rm -f conftest.$ac_objext conftest$ac_exeext
+ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+
+ cat >>confdefs.h <<\_ACEOF
+ #define HAVE_KRB5_FREE_UNPARSED_NAME 1
+ _ACEOF
+
+ echo "$as_me:$LINENO: result: yes" >&5
+ echo "${ECHO_T}yes" >&6
+ else
+ echo "$as_me: failed program was:" >&5
+ sed 's/^/| /' conftest.$ac_ext >&5
+
+ echo "$as_me:$LINENO: result: no" >&5
+ echo "${ECHO_T}no" >&6
+ fi
+ rm -f conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
fi
Index: configure.in
===================================================================
RCS file: /cvsroot/pgsql/configure.in,v
retrieving revision 1.518
diff -c -r1.518 configure.in
*** configure.in 10 Jul 2007 16:41:01 -0000 1.518
--- configure.in 12 Jul 2007 12:18:12 -0000
***************
*** 965,970 ****
--- 965,979 ----
[AC_MSG_ERROR([could not determine how to extract Kerberos 5 error messages])],
[#include <krb5.h>])],
[#include <krb5.h>])
+
+ # Win32 requires headers to be loaded for __stdcall, so can't use
+ # AC_CHECK_FUNCS here.
+ AC_MSG_CHECKING(for krb5_free_unparsed_name)
+ AC_TRY_LINK([#include <krb5.h>],
+ [krb5_free_unparsed_name(NULL,NULL);],
+ [AC_DEFINE(HAVE_KRB5_FREE_UNPARSED_NAME, 1, [Define to 1 if you have krb5_free_unparsed_name])
+ AC_MSG_RESULT(yes)],
+ [AC_MSG_RESULT(no)])
fi
Index: src/include/pg_config.h.in
===================================================================
RCS file: /cvsroot/pgsql/src/include/pg_config.h.in,v
retrieving revision 1.119
diff -c -r1.119 pg_config.h.in
*** src/include/pg_config.h.in 10 Jul 2007 16:41:01 -0000 1.119
--- src/include/pg_config.h.in 12 Jul 2007 12:19:14 -0000
***************
*** 214,219 ****
--- 214,222 ----
/* Define to 1 if `text.data' is member of `krb5_error'. */
#undef HAVE_KRB5_ERROR_TEXT_DATA
+ /* Define to 1 if you have krb5_free_unparsed_name */
+ #undef HAVE_KRB5_FREE_UNPARSED_NAME
+
/* Define to 1 if `client' is member of `krb5_ticket'. */
#undef HAVE_KRB5_TICKET_CLIENT
Index: src/interfaces/libpq/fe-auth.c
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v
retrieving revision 1.124
diff -c -r1.124 fe-auth.c
*** src/interfaces/libpq/fe-auth.c 10 Jul 2007 13:14:21 -0000 1.124
--- src/interfaces/libpq/fe-auth.c 12 Jul 2007 12:19:18 -0000
***************
*** 64,69 ****
--- 64,81 ----
#endif
/*
+ * Heimdal doesn't have a free function for unparsed names. Just pass it to
+ * standard free() which should work in these cases.
+ */
+ #ifndef HAVE_KRB5_FREE_UNPARSED_NAME
+ static void
+ krb5_free_unparsed_name(krb5_context context, char *val)
+ {
+ free(val);
+ }
+ #endif
+
+ /*
* pg_an_to_ln -- return the local name corresponding to an authentication
* name
*
***************
*** 180,187 ****
{
krb5_free_principal(info->pg_krb5_context, info->pg_krb5_client);
krb5_cc_close(info->pg_krb5_context, info->pg_krb5_ccache);
krb5_free_context(info->pg_krb5_context);
- free(info->pg_krb5_name);
}
--- 192,199 ----
{
krb5_free_principal(info->pg_krb5_context, info->pg_krb5_client);
krb5_cc_close(info->pg_krb5_context, info->pg_krb5_ccache);
+ krb5_free_unparsed_name(info->pg_krb5_context, info->pg_krb5_name);
krb5_free_context(info->pg_krb5_context);
}
Magnus Hagander <magnus@hagander.net> writes:
Thanks for the pointer. Attached is what I came up with. If someone
autoconfy can sign off on that it seems correct, I'll apply that.
Looks reasonable to me.
regards, tom lane
On Thu, Jul 12, 2007 at 09:54:28AM -0400, Tom Lane wrote:
Magnus Hagander <magnus@hagander.net> writes:
Thanks for the pointer. Attached is what I came up with. If someone
autoconfy can sign off on that it seems correct, I'll apply that.Looks reasonable to me.
Thanks, applied and backpatched to 8.2.
I didn't backpatch past 8.2, since I've only seen the bug affecting Windows
systems. Though it's actually incorrect code in 8.1 and earlier as well, I
figured we'd better leave it alone for now.
//Magnus