From 1cdc1a6737e94f887076c6eec9a62cc7801b13ad Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Sun, 15 Nov 2009 05:29:03 +0000 Subject: [PATCH] 1) Added --with(out)-libpq[=DIR} option to configure. 2) Revise autoconf/automake so that libpq/ssl header/libs are resolved at configure phase. 3) Use md5.c directly instead of win_md5.c. 4) Suppress some compiler warnings. --- Makefile.am | 9 +--- configure.ac | 103 +++++++++++++++++++++++++++++----------- connection.c | 5 +- installer/psqlodbcm.wxs | 2 +- loadlib.c | 3 +- loadlib.h | 2 +- md5.c | 32 +++++-------- socket.h | 5 +- version.h | 2 +- win32.mak | 2 +- win64.mak | 2 +- 11 files changed, 103 insertions(+), 64 deletions(-) diff --git a/Makefile.am b/Makefile.am index 90d9a8b..3d92bf2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ # # Makefile.am for psqlodbc30w (PostgreSQL ODBC driver) # -# $Header: /home/heikki/psqlodbc-cvs-copy/psqlodbc/Makefile.am,v 1.52 2009/03/20 15:39:22 hinoue Exp $ +# $Header: /home/heikki/psqlodbc-cvs-copy/psqlodbc/Makefile.am,v 1.53 2009/11/15 05:29:03 hinoue Exp $ # #------------------------------------------------------------------------- @@ -22,12 +22,9 @@ endif AM_LDFLAGS = -module -no-undefined -avoid-version -psqlodbca_la_LIBADD = -lpq -lssl -psqlodbcw_la_LIBADD = -lpq -lssl - psqlodbca_la_SOURCES = \ info.c bind.c columninfo.c connection.c convert.c drvconn.c \ - environ.c execute.c lobj.c win_md5.c misc.c options.c \ + environ.c execute.c lobj.c md5.c misc.c options.c \ pgtypes.c psqlodbc.c qresult.c results.c socket.c parse.c \ statement.c tuple.c dlg_specific.c loadlib.c \ multibyte.c odbcapi.c descriptor.c \ @@ -42,8 +39,6 @@ psqlodbca_la_SOURCES = \ psqlodbcw_la_SOURCES = $(psqlodbca_la_SOURCES) \ odbcapi30w.c odbcapiw.c win_unicode.c -EXTRA_psqlodbca_la_SOURCES = md5.c -EXTRA_psqlodbcw_la_SOURCES = md5.c EXTRA_DIST = license.txt readme.txt \ libtool.m4 psqlodbc.def psqlodbca.def \ diff --git a/configure.ac b/configure.ac index bc9e9a5..b7ed818 100644 --- a/configure.ac +++ b/configure.ac @@ -12,7 +12,7 @@ AM_MAINTAINER_MODE # -# Decide which unixODBC driver manager to use +# Whether unixODBC driver manager is used # AC_ARG_WITH(unixodbc, [ --with-unixodbc=DIR odbc_config installation of unixODBC (default)], [ @@ -36,7 +36,7 @@ AC_ARG_WITH(unixodbc, [ --with-unixodbc=DIR odbc_config installation of uni # -# Decide which iODBC driver manager to use +# Whether iODBC driver manager is used # AC_ARG_WITH(iodbc, [ --with-iodbc=DIR iodbc_config installation of iODBC], [ @@ -71,19 +71,6 @@ if test "$with_unixodbc" = yes; then [Define to use wchar_t as SQLWCHAR in unixODBC]) fi -# -# SQLCOLATTRIBUTE_SQLLEN check -# -AC_COMPILE_IFELSE([AC_LANG_PROGRAM( - [[#include > - SQLRETURN SQL_API SQLColAttribute - (SQLHSTMT StatementHandle,SQLUSMALLINT ColumnNumber, - SQLUSMALLINT FieldIdentifier, SQLPOINTER CharacterAttribute, - SQLSMALLINT BufferLength, SQLSMALLINT *StringLength, - SQLLEN *NumercAttribute);]],[[]])],[], - AC_DEFINE(SQLCOLATTRIBUTE_SQLLEN, 1, - [Define to 1 if SQLColAttribute use SQLLEN])) - # # ODBC include and library # @@ -103,6 +90,50 @@ if test "$ODBC_CONFIG" != ""; then AC_MSG_NOTICE([using $ODBC_INCLUDE $ODBC_LIBS]) fi +# +# SQLCOLATTRIBUTE_SQLLEN check +# +AC_COMPILE_IFELSE([AC_LANG_PROGRAM( + [[#include > + SQLRETURN SQL_API SQLColAttribute + (SQLHSTMT StatementHandle,SQLUSMALLINT ColumnNumber, + SQLUSMALLINT FieldIdentifier, SQLPOINTER CharacterAttribute, + SQLSMALLINT BufferLength, SQLSMALLINT *StringLength, + SQLLEN *NumercAttribute);]],[[]])], + AC_DEFINE(SQLCOLATTRIBUTE_SQLLEN, 1, + [Define to 1 if SQLColAttribute use SQLLEN])) + + +# +# Whether libpq functionalities are used +# +AC_ARG_WITH(libpq, [ --with-libpq[[=DIR]] [[default=yes]] DIR is the PostgreSQL base install + directory or the path to pg_config + --without-libpq specify when PostgreSQL package isn't installed], +[ + if test "$withval" = no; then + AC_DEFINE(NOT_USE_LIBPQ, 1, + [Define to 1 to build without libpq]) + enable_openssl=no + else + if test "$withval" != yes; then + if test -d "$withval"; then + PATH="$PATH:$withval/bin" + CPPFLAGS="$CPPFLAGS -I$withval/include" + LDFLAGS="$LDFLAGS -L$withval/lib" + else + if test -x "$withval"; then + PG_CONFIG=$withval + else + AC_MSG_ERROR([specified pg_config not found]) + fi + fi + fi + with_libpq=yes + fi + ], +[with_libpq=yes]) + # # Default odbc version number (--with-odbcver), default 0x0351 @@ -154,17 +185,19 @@ PGAC_ARG_BOOL(enable, pthreads, yes, # Find libpq headers and libraries # -AC_PATH_PROGS(PG_CONFIG, pg_config) +if test "$with_libpq" = yes; then + if test -z "$PG_CONFIG"; then + AC_PATH_PROGS(PG_CONFIG, pg_config) + fi -if test -z "$PG_CONFIG"; then - AC_MSG_ERROR([pg_config not found (set PG_CONFIG environment variable)]) + if test -n "$PG_CONFIG"; then + pg_includedir=`"$PG_CONFIG" --includedir` + pg_libdir=`"$PG_CONFIG" --libdir` + CPPFLAGS="$CPPFLAGS -I$pg_includedir" + LDFLAGS="$LDFLAGS -L$pg_libdir" + fi fi -pg_includedir=`"$PG_CONFIG" --includedir` -pg_libdir=`"$PG_CONFIG" --libdir` -CPPFLAGS="$CPPFLAGS -I$pg_includedir" -LDFLAGS="$LDFLAGS -L$pg_libdir" - # 1. Programs @@ -196,10 +229,25 @@ if test "$enable_pthreads" = yes; then [AC_CHECK_LIB(pthread, pthread_create)]) fi +if test "$with_libpq" = yes; then + AC_CHECK_LIB(pq, PQconnectdb, [], + [AC_MSG_ERROR([libpq library not found])]) +fi + +if test "$enable_openssl" = yes; then + AC_CHECK_LIB(ssl, SSL_read, [], [AC_MSG_ERROR([ssl library not found])]) +fi + # 3. Header files AC_CHECK_HEADERS(locale.h sys/un.h sys/time.h) +if test "$with_libpq" = yes; then + AC_CHECK_HEADER(libpq-fe.h,,[AC_MSG_ERROR([libpq header not found])]) +fi +if test "$enable_openssl" = yes; then + AC_CHECK_HEADER([openssl/ssl.h],,[AC_MSG_ERROR([ssl header not found])]) +fi AC_HEADER_TIME @@ -214,7 +262,6 @@ AC_CHECK_TYPES(signed char) AC_CHECK_TYPES(ssize_t) AC_TYPE_SIZE_T - # 5. Structures AC_STRUCT_TM @@ -239,12 +286,12 @@ if test "$enable_pthreads" = yes; then AC_CHECK_FUNCS(localtime_r strtok_r pthread_mutexattr_settype) if test x"$ac_cv_func_pthread_mutexattr_settype" = xyes; then - AC_TRY_COMPILE([#include ], - [int i = PTHREAD_MUTEX_RECURSIVE;], + AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[#include ]], + [[int i = PTHREAD_MUTEX_RECURSIVE;]]), [AC_DEFINE(PG_RECURSIVE_MUTEXATTR, PTHREAD_MUTEX_RECURSIVE, [Define if you have PTHREAD_MUTEX_RECURSIVE])], - [AC_TRY_COMPILE([#include ], - [int i = PTHREAD_MUTEX_RECURSIVE_NP;], + [AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[#include ]], + [[int i = PTHREAD_MUTEX_RECURSIVE_NP;]]), [AC_DEFINE(PG_RECURSIVE_MUTEXATTR, PTHREAD_MUTEX_RECURSIVE_NP, [Define if you have PTHREAD_MUTEX_RECURSIVE_NP])])]) fi diff --git a/connection.c b/connection.c index dda67d6..e628ace 100644 --- a/connection.c +++ b/connection.c @@ -14,10 +14,11 @@ */ /* Multibyte support Eiji Tokuya 2001-03-15 */ +#include "loadlib.h" +#include "connection.h" #ifndef NOT_USE_LIBPQ #include #endif /* NOT_USE_LIBPQ */ -#include "connection.h" #include #include @@ -1198,6 +1199,7 @@ static int protocol3_packet_build(ConnectionClass *self) return 1; } +#ifndef NOT_USE_LIBPQ CSTR l_login_timeout = "connect_timeout"; static char *protocol3_opts_build(ConnectionClass *self) { @@ -1267,6 +1269,7 @@ static char *protocol3_opts_build(ConnectionClass *self) inolog("return conninfo=%s(%d)\n", conninfo, strlen(conninfo)); return conninfo; } +#endif /* NOT_USE_LIBPQ */ static char CC_initial_log(ConnectionClass *self, const char *func) { diff --git a/installer/psqlodbcm.wxs b/installer/psqlodbcm.wxs index fd280d0..40ede49 100644 --- a/installer/psqlodbcm.wxs +++ b/installer/psqlodbcm.wxs @@ -27,7 +27,7 @@ - + diff --git a/loadlib.c b/loadlib.c index 2223f24..1abd70d 100644 --- a/loadlib.c +++ b/loadlib.c @@ -14,13 +14,14 @@ #ifndef WIN32 #include #endif /* WIN32 */ + +#include "loadlib.h" #ifndef NOT_USE_LIBPQ #ifdef RESET_CRYPTO_CALLBACKS #include #endif /* RESET_CRYPTO_CALLBACKS */ #include #endif /* NOT_USE_LIBPQ */ -#include "loadlib.h" #include "pgenlist.h" #ifdef WIN32 diff --git a/loadlib.h b/loadlib.h index 0f15195..3cfd710 100644 --- a/loadlib.h +++ b/loadlib.h @@ -26,8 +26,8 @@ extern "C" { BOOL SSLLIB_check(void); #ifndef NOT_USE_LIBPQ void *CALL_PQconnectdb(const char *conninfo, BOOL *); -BOOL ssl_verify_available(void); #endif /* NOT_USE_LIBPQ */ +BOOL ssl_verify_available(void); #ifdef _HANDLE_ENLIST_IN_DTC_ RETCODE CALL_EnlistInDtc(ConnectionClass *conn, void * pTra, int method); RETCODE CALL_DtcOnDisconnect(ConnectionClass *); diff --git a/md5.c b/md5.c index da327e7..4ec0df0 100644 --- a/md5.c +++ b/md5.c @@ -14,31 +14,18 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /home/heikki/psqlodbc-cvs-copy/psqlodbc/md5.c,v 1.12 2006/09/13 15:30:27 hinoue Exp $ + * $Header: /home/heikki/psqlodbc-cvs-copy/psqlodbc/md5.c,v 1.13 2009/11/15 05:29:03 hinoue Exp $ */ /* * NOTE: * - * There are two copies of this file, one in backend/libpq and another - * in interfaces/odbc. They should be identical. This is done so ODBC - * can be compiled stand-alone. + * This file was copied from backend/libpq once. */ -#ifndef MD5_ODBC -#include "postgres.h" -#include "libpq/crypt.h" -#else #include "md5.h" -#endif -#ifdef FRONTEND -#undef palloc -#define palloc malloc -#undef pfree -#define pfree free -#endif /* @@ -262,7 +249,7 @@ calculateDigestFromBuffer(uint8 *b, uint32 len, uint8 sum[16]) static void bytesToHex(uint8 b[16], char *s) { - static char *hex = "0123456789abcdef"; + static const char *hex = "0123456789abcdef"; int q, w; @@ -296,8 +283,8 @@ bytesToHex(uint8 b[16], char *s) * characters. you thus need to provide an array * of 33 characters, including the trailing '\0'. * - * RETURNS 0 on failure (out of memory for internal buffers) or - * non-zero on success. + * RETURNS false on failure (out of memory for internal buffers) or + * true on success. * * STANDARDS MD5 is described in RFC 1321. * @@ -332,20 +319,23 @@ EncryptMD5(const char *passwd, const char *salt, size_t salt_len, char *buf) { size_t passwd_len = strlen(passwd); - char *crypt_buf = palloc(passwd_len + salt_len); + char *crypt_buf = malloc(passwd_len + salt_len + 1); bool ret; + if (!crypt_buf) + return false; + /* * Place salt at the end because it may be known by users trying to * crack the MD5 output. */ - strcpy(crypt_buf, passwd); + memcpy(crypt_buf, passwd, passwd_len); memcpy(crypt_buf + passwd_len, salt, salt_len); strcpy(buf, "md5"); ret = md5_hash(crypt_buf, passwd_len + salt_len, buf + 3); - pfree(crypt_buf); + free(crypt_buf); return ret; } diff --git a/socket.h b/socket.h index 964a3d8..0cf7d47 100644 --- a/socket.h +++ b/socket.h @@ -98,7 +98,10 @@ struct addrinfo #endif /* WIN32 */ typedef void (WSAAPI *freeaddrinfo_func) (struct addrinfo *); typedef int (WSAAPI *getaddrinfo_func) (const char *, const char *, - const struct addrinfo *, struct addrinfo **); +#ifndef __CYGWIN__ + const +#endif + struct addrinfo *, struct addrinfo **); typedef int (WSAAPI *getnameinfo_func) (const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int); diff --git a/version.h b/version.h index 63df9c1..f6be117 100644 --- a/version.h +++ b/version.h @@ -12,6 +12,6 @@ #define POSTGRESDRIVERVERSION "08.04.0101" #define POSTGRES_RESOURCE_VERSION "08.04.0101\0" #define PG_DRVFILE_VERSION 8,4,01,01 -#define PG_BUILD_VERSION "200910250005" +#define PG_BUILD_VERSION "200911150001" #endif diff --git a/win32.mak b/win32.mak index 74b4660..0b79710 100644 --- a/win32.mak +++ b/win32.mak @@ -290,7 +290,7 @@ LINK32_OBJS= \ "$(INTDIR)\info.obj" \ "$(INTDIR)\info30.obj" \ "$(INTDIR)\lobj.obj" \ - "$(INTDIR)\win_md5.obj" \ + "$(INTDIR)\md5.obj" \ "$(INTDIR)\misc.obj" \ "$(INTDIR)\mylog.obj" \ "$(INTDIR)\pgapi30.obj" \ diff --git a/win64.mak b/win64.mak index 92eda78..ef08dbc 100755 --- a/win64.mak +++ b/win64.mak @@ -276,7 +276,7 @@ LINK32_OBJS= \ "$(INTDIR)\info.obj" \ "$(INTDIR)\info30.obj" \ "$(INTDIR)\lobj.obj" \ - "$(INTDIR)\win_md5.obj" \ + "$(INTDIR)\md5.obj" \ "$(INTDIR)\misc.obj" \ "$(INTDIR)\mylog.obj" \ "$(INTDIR)\pgapi30.obj" \ -- 2.39.5