Thread: [psqlODBC 08.02.0402] OpenSSL libraries

[psqlODBC 08.02.0402] OpenSSL libraries

From
Rainer Bauer
Date:
Hi,

I checked out the latest head version today 08.02.0402 to find a solution for
the new OpenSSL DLL naming scheme.

I wanted to produce a patch for loadlib.c based on the following idea:

1) Include openssl/opensslv.h
2) Based on the version number OPENSSL_VERSION_NUMBER defined in that file
either link with ssleay32.lib or ssleay32MT.lib (respectively libeay32.lib or
libeay32MT.lib).

But I stopped doing this, because ...
1) according to the OpenSSL FAQ, the DLL naming scheme was changed for version
0.9.8: <http://www.openssl.org/support/faq.html#PROG2>
2) the OpenSSL DLLs installed by the MSI installer are versions 0.9.8.4.

Hence somebody must have renamed the DLLs before they were added to the
installer.

So what we can do is either stick with the old names and manually
copying/renaming them or switch completely to the new names. The former
requires renaming the DLLs in order to build the project (which should be
documented in ~/docs/win32-compilation.html), the latter requires altering the
MSI installer (are there any pitfalls doing that?).

Rainer

PS: Can someone shed some light why delay loading is used in loadlib.c?

Re: [psqlODBC 08.02.0402] OpenSSL libraries

From
Hiroshi Inoue
Date:
Rainer Bauer wrote:
> Hi,
>
> I checked out the latest head version today 08.02.0402 to find a solution for
> the new OpenSSL DLL naming scheme.

Do you get OpenSSL libraries from
http://www.slproweb.com/products/Win32OpenSSL.html ?
Though I can find ssleay32(MT]MD)(d).lib in C:\OpenSSL\lib\vc, I can't
find ssleay32(MT|MD)(d).dll. What's the differnce among ssleay32xx.lib ?

> I wanted to produce a patch for loadlib.c based on the following idea:
>
> 1) Include openssl/opensslv.h
> 2) Based on the version number OPENSSL_VERSION_NUMBER defined in that file
> either link with ssleay32.lib or ssleay32MT.lib (respectively libeay32.lib or
> libeay32MT.lib).
>
> But I stopped doing this, because ...
> 1) according to the OpenSSL FAQ, the DLL naming scheme was changed for version
> 0.9.8: <http://www.openssl.org/support/faq.html#PROG2>
> 2) the OpenSSL DLLs installed by the MSI installer are versions 0.9.8.4.
>
> Hence somebody must have renamed the DLLs before they were added to the
> installer.
>
> So what we can do is either stick with the old names and manually
> copying/renaming them or switch completely to the new names. The former
> requires renaming the DLLs in order to build the project (which should be
> documented in ~/docs/win32-compilation.html), the latter requires altering the
> MSI installer (are there any pitfalls doing that?).
>
> Rainer
>
> PS: Can someone shed some light why delay loading is used in loadlib.c?

Because the driver can live without libpq, ssleay32 or pgenlist.
If you use SSL connections, libpq and ssleay32 are loaded dynamically.
If you enlist in MSDTC, pgenlist(a) is loaeded dynamically.

Re: [psqlODBC 08.02.0402] OpenSSL libraries

From
Rainer Bauer
Date:
Hiroshi Inoue wrote:

>Rainer Bauer wrote:
>> I checked out the latest head version today 08.02.0402 to find a solution for
>> the new OpenSSL DLL naming scheme.
>
>Do you get OpenSSL libraries from
>http://www.slproweb.com/products/Win32OpenSSL.html ?

Yes.

>Though I can find ssleay32(MT]MD)(d).lib in C:\OpenSSL\lib\vc, I can't
>find ssleay32(MT|MD)(d).dll. What's the differnce among ssleay32xx.lib ?

Sorry this was my fault.: I didn't search for the DLLs installed by OpenSSL.
The difference between /MT and /MD is explained here:
<http://msdn2.microsoft.com/en-us/library/2kzt1wy3(VS.80).aspx>
The /MT option defines _MT whereas the /MD option defines _MT and _DLL
resulting in different runtimes being linked.

According to the FAQ <http://www.openssl.org/support/faq.html#PROG2>, psqlODBC
should contain the code for OPENSSL_Applink() (see also
<http://www.openssl.org/docs/crypto/OPENSSL_Applink.html>), because it is
linked with a different setting. But that is not the case!

So there are a few open questions:
Why is psqlODBC build with /MT and not /MD?
Why are SSL connections working at all (I assume they are, since I cannot test
it here), if the OpenSSL DLLs and psqlODBC are linked to different runtimes?

Regardless of these issues, my approach would make sense (the DLLs are not
renamed), we just have to include the correct lib files in loadlib.c based on
the installed OpenSSL version:

>> I wanted to produce a patch for loadlib.c based on the following idea:
>>
>> 1) Include openssl/opensslv.h
>> 2) Based on the version number OPENSSL_VERSION_NUMBER defined in that file
>> either link with ssleay32.lib or ssleay32MT.lib (respectively libeay32.lib or
>> libeay32MT.lib).


>> PS: Can someone shed some light why delay loading is used in loadlib.c?
>
>Because the driver can live without libpq, ssleay32 or pgenlist.
>If you use SSL connections, libpq and ssleay32 are loaded dynamically.
>If you enlist in MSDTC, pgenlist(a) is loaeded dynamically.

I see.

Another question: How many active developers are there for Win32? And what
compilers are they using? Dopping support for VC6 would clean up the code (at
least in loadlib.c and the makefile).

Rainer

Re: [psqlODBC 08.02.0402] OpenSSL libraries

From
Hiroshi Inoue
Date:
Rainer Bauer wrote:
> Hiroshi Inoue wrote:
>
>> Rainer Bauer wrote:
>>> I checked out the latest head version today 08.02.0402 to find a solution for
>>> the new OpenSSL DLL naming scheme.
>> Do you get OpenSSL libraries from
>> http://www.slproweb.com/products/Win32OpenSSL.html ?
>
> Yes.
>
>> Though I can find ssleay32(MT]MD)(d).lib in C:\OpenSSL\lib\vc, I can't
>> find ssleay32(MT|MD)(d).dll. What's the differnce among ssleay32xx.lib ?
>
> Sorry this was my fault.: I didn't search for the DLLs installed by OpenSSL.
> The difference between /MT and /MD is explained here:
> <http://msdn2.microsoft.com/en-us/library/2kzt1wy3(VS.80).aspx>
> The /MT option defines _MT whereas the /MD option defines _MT and _DLL
> resulting in different runtimes being linked.
>
> According to the FAQ <http://www.openssl.org/support/faq.html#PROG2>, psqlODBC
> should contain the code for OPENSSL_Applink() (see also

Shouldn't it be added to the EXE project not to the DLL one ?

> <http://www.openssl.org/docs/crypto/OPENSSL_Applink.html>), because it is
> linked with a different setting. But that is not the case!
>
> So there are a few open questions:
> Why is psqlODBC build with /MT and not /MD?

Because it has been so without problems.

I'm pretty confused. Is it realistic to expect all the relevant dlls
and the exe itself are compiled with the same option settings and
compiler ? For example, if we build it with /MD otpion using vc8.0,
the driver would link msvcr(p)80.dll. OTOH ssleay32.dll downloaded
from http://www.slproweb.com/products/Win32OpenSSL.html seems to
be linking msvcr71.dll. Is there no problem with it ?

> Why are SSL connections working at all (I assume they are, since I cannot test
> it here), if the OpenSSL DLLs and psqlODBC are linked to different runtimes?

It's not that easy to crash programs with the mixed options and
I don't know definite problems to mix the options.
OPENSSL_Applink() may be the hint.

> Regardless of these issues, my approach would make sense (the DLLs are not
> renamed), we just have to include the correct lib files in loadlib.c based on
> the installed OpenSSL version:
>
>>> I wanted to produce a patch for loadlib.c based on the following idea:
>>>
>>> 1) Include openssl/opensslv.h
>>> 2) Based on the version number OPENSSL_VERSION_NUMBER defined in that file
>>> either link with ssleay32.lib or ssleay32MT.lib (respectively libeay32.lib or
>>> libeay32MT.lib).
>
>
>>> PS: Can someone shed some light why delay loading is used in loadlib.c?
>> Because the driver can live without libpq, ssleay32 or pgenlist.
>> If you use SSL connections, libpq and ssleay32 are loaded dynamically.
>> If you enlist in MSDTC, pgenlist(a) is loaeded dynamically.
>
> I see.
>
> Another question: How many active developers are there for Win32? And what
> compilers are they using? Dopping support for VC6 would clean up the code (at
> least in loadlib.c and the makefile).

Please look at
    http://pgfoundry.org/project/memberlist.php?group_id=1000125.

The code is mainly maintained by me.
I'm using VC7.1 mainly.
AFAIK Hiroshi Saito can use both VC6 and VC8.

regards,
Hiroshi Inoue

Re: [psqlODBC 08.02.0402] OpenSSL libraries

From
Rainer Bauer
Date:
Hiroshi Inoue wrote:
>> According to the FAQ <http://www.openssl.org/support/faq.html#PROG2>, psqlODBC
>> should contain the code for OPENSSL_Applink() (see also
>
>Shouldn't it be added to the EXE project not to the DLL one ?

Seems so [see replay from Andy Polyakov]:
<http://groups.google.com/group/mailing.openssl.users/browse_thread/thread/2c53d4dbd7545255/875519825b7dea09>

"... in the [export] symbol table of the *application*. The applink.c
module has to be linked into *application,* not some other dll, even if
it's dll that links with openssl dll and not application itself."

>> Why is psqlODBC build with /MT and not /MD?
>
>Because it has been so without problems.
>
>I'm pretty confused. Is it realistic to expect all the relevant dlls
>and the exe itself are compiled with the same option settings and
>compiler ? For example, if we build it with /MD otpion using vc8.0,
>the driver would link msvcr(p)80.dll. OTOH ssleay32.dll downloaded
>from http://www.slproweb.com/products/Win32OpenSSL.html seems to
>be linking msvcr71.dll. Is there no problem with it ?

There shouldn't, as long as there is no memory allocated/freed across modules
compiled with different runtimes.

Time to test this:
I have activated SSL in my local Postgres 8.2.4 installation
[postgresql.conf]. After creating and installing the server certificate,
restarting Postgres and specifying "SSLmode=require" in the ODBC connection
string I was able to establish a SSL connection through ODBC.

So SSL is working, *but* then happened what I had expected: at program exit
the program core dumps while freeing memory. I can see that this happens in
libeay32.dll.

What I did next was adding the OPENSSL_Applink() code snippet to my
application code. It still crashed.

I tried linking the psqlODBC driver with all four different OpenSSL libs found
in the C:\OpenSSL\lib\VC folder. It still crashed.

Next I replaced the OpenSSL DLLs [0.9.8.4] in the psqlODBC installation with
the ones shipped with my OpenSSL installation [0.9.8.5]. It still crashed.

Before investigating this any further I must ask if anybody has ever used an
SSL connection with psqlODBC?

>> Why are SSL connections working at all (I assume they are, since I cannot test
>> it here), if the OpenSSL DLLs and psqlODBC are linked to different runtimes?
>
>It's not that easy to crash programs with the mixed options and
>I don't know definite problems to mix the options.
>OPENSSL_Applink() may be the hint.

Do you have a Win32 program that establishes a SSL connection and does NOT
crash? If so could you send me the source so that I can verify it here?

Rainer

PS: psqlODBC only calls SSL_read(), SSL_write() and SSL_get_error(). As I
understand it all the real SSL handling happens in libpq. So maybe I am
looking at the wrong place to find the error?

Re: [psqlODBC 08.02.0402] OpenSSL libraries

From
Hiroshi Inoue
Date:
Rainer Bauer wrote:
>
> Do you have a Win32 program that establishes a SSL connection and does NOT
> crash?

For example MS Access. Unfortunately we can't expect to add
  OPENSSL_Applink() code snippet to such generic applications.

> Rainer
>
> PS: psqlODBC only calls SSL_read(), SSL_write() and SSL_get_error(). As I
> understand it all the real SSL handling happens in libpq. So maybe I am
> looking at the wrong place to find the error?

Psqlodbc uses libpq to establish SSL connections and gets the result
communication path using PQsocket() and/or PQgetssl(). Then
the driver communcates with the server via the commnication path
and doesn't call libpq APIs until the end of the connection.
The driver calls PQfinish() to terminate the connection.

It would be a problem if libpq and psqlodbc link different openssl
libraries.

regards,
Hiroshi Inoue

DSNLess connection

From
"Benjamin Krajmalnik"
Date:
I would like to create a DSNless connection from within my application.
I did not see any documentation concerning this other than the VBA
example.
My questio relates more to the additional parameters, which in the
example code are being passed as A0, A1, etc.
Is this the convention which I should be using?

Re: DSNLess connection

From
"Hiroshi Saito"
Date:
Hi.

This may help you.
http://cvs.pgfoundry.org/cgi-bin/cvsweb.cgi/psqlodbc/psqlodbc/dlg_specific.h?annotate=1.55
However, we will need to consider setting it on a document....
Thanks!

Regards,
Hiroshi Saito

----- Original Message -----
From: "Benjamin Krajmalnik"

I would like to create a DSNless connection from within my application.
I did not see any documentation concerning this other than the VBA
example.
My questio relates more to the additional parameters, which in the
example code are being passed as A0, A1, etc.
Is this the convention which I should be using?

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Re: [psqlODBC 08.02.0402] OpenSSL libraries

From
Rainer Bauer
Date:
Hiroshi Inoue wrote:
>> Do you have a Win32 program that establishes a SSL connection and does NOT
>> crash?
>
>For example MS Access. Unfortunately we can't expect to add
>  OPENSSL_Applink() code snippet to such generic applications.

Well, if SSL connections do work with MS Access, then the error must be
somewhere else.

How do you test the driver during developement? Are you using Access or a
handwritten program?

>> PS: psqlODBC only calls SSL_read(), SSL_write() and SSL_get_error(). As I
>> understand it all the real SSL handling happens in libpq. So maybe I am
>> looking at the wrong place to find the error?
>
>Psqlodbc uses libpq to establish SSL connections and gets the result
>communication path using PQsocket() and/or PQgetssl(). Then
>the driver communcates with the server via the commnication path
>and doesn't call libpq APIs until the end of the connection.
>The driver calls PQfinish() to terminate the connection.
>
>It would be a problem if libpq and psqlodbc link different openssl
>libraries.

What I did was installing Postgres 8.2.4 _without_ the psqlODBC driver.
Afterwards I downloaded the latest MSI package [8.2.0400] from the psqlODBC
page and installed that version. Any chance that there are some
incompatibilites introduced by that?

Rainer

Re: [psqlODBC 08.02.0402] OpenSSL libraries

From
Rainer Bauer
Date:
I wrote:

>What I did was installing Postgres 8.2.4 _without_ the psqlODBC driver.
>Afterwards I downloaded the latest MSI package [8.2.0400] from the psqlODBC
>page and installed that version.

... and in the meantime the ODBC driver was compiled from the 8.2.0402 source.

So I went and restored the original psqlodbc30a.dll and the SSL connection
works. Hence compiling the psqlODBC driver craches when compiled with VS2005.

Any pointer where I could start looking what goes wrong?

This is the command I use to build the driver:
nmake /f win32.mak CFG=Debug ANSI_VERSION=yes MSDTC=no ALL

Could you send send me offlist the (debug/release) your DLLs from 8.2.0402 so
I could verify whether they are working?

Rainer

Re: [psqlODBC 08.02.0402] OpenSSL libraries

From
Rainer Bauer
Date:
Hiroshi Inoue wrote:

>> Any pointer where I could start looking what goes wrong?
>>
>> This is the command I use to build the driver:
>> nmake /f win32.mak CFG=Debug ANSI_VERSION=yes MSDTC=no ALL
>>
>Hmm I  rarely use the Debug version and  I'm not sure about it.

I get the same error if I compile the release version.

Could you please send me the exact command you are using to build the ANSI
driver?

>> Could you send send me offlist the (debug/release) your DLLs from 8.2.0402 so
>> I could verify whether they are working?
>
>I attached the debug and release dlls.

Both are working.

So this is either a VS2005 specific problem or the problem is caused by the
OpenSSL version I am using.

Rainer

Re: [psqlODBC 08.02.0402] OpenSSL libraries

From
Hiroshi Inoue
Date:
Rainer Bauer wrote:
> Hiroshi Inoue wrote:
>
>>> Any pointer where I could start looking what goes wrong?
>>>
>>> This is the command I use to build the driver:
>>> nmake /f win32.mak CFG=Debug ANSI_VERSION=yes MSDTC=no ALL
>>>
>> Hmm I  rarely use the Debug version and  I'm not sure about it.
>
> I get the same error if I compile the release version.
>
> Could you please send me the exact command you are using to build the ANSI
> driver?

I'm using the same command line as you write above.
Anyway I found a crash bug and committed the fix.
Please try the snapshot again.

regards,
Hiroshi Inoue


Connection Pooling

From
"Benjamin Krajmalnik"
Date:
Does the latest version of the ODBC driver for windows support
connection pooling?

Re: Connection Pooling

From
Andrei Kovalevski
Date:
    Hello,

    Connection pooling was introduced in ODBC 3.0. It is ODBC driver
manager's relative feature. If the driver is thread-safe - then ODBC
Driver Manager will be able to use it in Connection pooling. All known
PostgreSQL ODBC drivers are thread-safe. This page could help you to
answer some of your questions - http://support.microsoft.com/kb/169470.

Benjamin Krajmalnik wrote:
> Does the latest version of the ODBC driver for windows support
> connection pooling?
>
--
Andrei Kovalevski
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/