Skip site navigation (1) Skip section navigation (2)

Patch for ODBC driver (look for odbc.ini in more than one location)

From: "Ross Thomas" <ross(at)grinfinity(dot)com>
To: <pgsql-patches(at)postgresql(dot)org>
Subject: Patch for ODBC driver (look for odbc.ini in more than one location)
Date: 2001-12-09 19:11:42
Message-ID: 001201c180e5$5695ab80$0264a8c0@home.lan (view raw or whole thread)
Lists: pgsql-patches
Since most ODBC drivers and driver managers look for odbc.ini in several
locations on UNIX systems, it would seem sensible to have the PostgreSQL
driver do the same thing. (This idea occurred to me after five hours of
trying to figure out what libpsqlodbc didn't like about my /etc/odbc.ini,
but that's another story.)

iODBC, for example, does the following:

1) Checks $ODBCINI
2) Checks $HOME/.odbc.ini
3) Checks ~/.odbc.ini (where ~ is obtained from struct passwd)
4) Checks system-wide odbc.ini (in /etc by default)

This is essentially backwards-compatible with the old behaviour, unless
$ODBCINI is defined (in which case, arguably, the DBA knows what he's doing
anyway...). It resembles the Windows approach of allowing both user and
system data sources.

The attached patch implements this search path in 7.1.3's
GetPrivateProfileString(). It patches the following files:

It works for me (GNU/Linux i686). Possible issues include:

- Security. Since this library could (unwisely) be called from a setuid
binary, this is very important. How sensible is it to incorporate the
contents of an environment variable directly into the first argument to
fopen()? All relevant calls to fopen() are read-only (PG_BINARY_R).

- Portability. The new code shouldn't be any less portable than the 7.1.3
code, but I might have missed something.

- Consistency. Is the configure script option (--with-odbc=DIR) properly
named? I followed the convention set by --with-odbcinst, but the name I
chose could conceivably be confused with --enable-odbc. It might be more
appropriate (albeit less consistent) to call it --with-odbc-ini.

- Should one obtain the current user's home directory from /etc/passwd by
doing getpwuid(getuid()) or getpwuid(geteuid())? Currently I - like the
7.1.3 version of GetPrivateProfileString() - use the former, but it's
something worth thinking about.

- While I think I understand the somewhat convoluted code I replaced in
GetPrivateProfileString(), I am occasionally wrong. ;)

Feedback on these and any other issues would be very much appreciated.

Ross Thomas

Attachment: ini-search-patch
Description: application/octet-stream (6.4 KB)


pgsql-patches by date

Next:From: Karel ZakDate: 2001-12-10 10:09:04
Subject: Re: date formatting and tab-complete patch
Previous:From: Weiping HeDate: 2001-12-09 13:10:00
Subject: NLS (zh_CN) for pg_dump

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group