diff -crN postgresql-7.1.3.orig/configure.in postgresql-7.1.3/configure.in *** postgresql-7.1.3.orig/configure.in Sat Dec 8 21:22:31 2001 --- postgresql-7.1.3/configure.in Sat Dec 8 21:25:29 2001 *************** *** 537,542 **** --- 537,550 ---- AC_SUBST([odbcinst_ini_dir]) + # Allow for overriding the default location of the odbc.ini + # file which is normally ${sysconfdir} (i.e., ${prefix}/etc). + PGAC_ARG_REQ(with, odbc, + [ --with-odbc=DIR default directory for odbc.ini [sysconfdir]], + [odbc_ini_dir=$withval], + [odbc_ini_dir="\${sysconfdir}"]) + AC_SUBST([odbc_ini_dir]) + # Assume system is ELF if it predefines __ELF__ as 1, # otherwise believe host_os based default. diff -crN postgresql-7.1.3.orig/src/Makefile.global.in postgresql-7.1.3/src/Makefile.global.in *** postgresql-7.1.3.orig/src/Makefile.global.in Sat Dec 8 21:28:26 2001 --- postgresql-7.1.3/src/Makefile.global.in Sat Dec 8 21:29:10 2001 *************** *** 98,103 **** --- 98,104 ---- endif odbcinst_ini_dir = @odbcinst_ini_dir@ + odbc_ini_dir = @odbc_ini_dir@ ########################################################################## diff -crN postgresql-7.1.3.orig/src/interfaces/odbc/GNUmakefile postgresql-7.1.3/src/interfaces/odbc/GNUmakefile *** postgresql-7.1.3.orig/src/interfaces/odbc/GNUmakefile Sat Dec 8 21:20:21 2001 --- postgresql-7.1.3/src/interfaces/odbc/GNUmakefile Sat Dec 8 21:21:14 2001 *************** *** 15,21 **** SO_MAJOR_VERSION = 0 SO_MINOR_VERSION = 26 ! override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) -DHAVE_CONFIG_H -DODBCINSTDIR='"$(odbcinst_ini_dir)"' OBJS = info.o bind.o columninfo.o connection.o convert.o drvconn.o \ --- 15,21 ---- SO_MAJOR_VERSION = 0 SO_MINOR_VERSION = 26 ! override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) -DHAVE_CONFIG_H -DODBCINSTDIR='"$(odbcinst_ini_dir)"' -DODBCDIR='"$(odbc_ini_dir)"' OBJS = info.o bind.o columninfo.o connection.o convert.o drvconn.o \ diff -crN postgresql-7.1.3.orig/src/interfaces/odbc/dlg_specific.h postgresql-7.1.3/src/interfaces/odbc/dlg_specific.h *** postgresql-7.1.3.orig/src/interfaces/odbc/dlg_specific.h Sat Dec 8 21:02:22 2001 --- postgresql-7.1.3/src/interfaces/odbc/dlg_specific.h Sat Dec 8 21:02:37 2001 *************** *** 30,36 **** /* INI File Stuff */ #ifndef WIN32 ! #define ODBC_INI ".odbc.ini" #ifdef ODBCINSTDIR #define ODBCINST_INI ODBCINSTDIR "/odbcinst.ini" #else --- 30,36 ---- /* INI File Stuff */ #ifndef WIN32 ! #define ODBC_INI "odbc.ini" #ifdef ODBCINSTDIR #define ODBCINST_INI ODBCINSTDIR "/odbcinst.ini" #else diff -crN postgresql-7.1.3.orig/src/interfaces/odbc/gpps.c postgresql-7.1.3/src/interfaces/odbc/gpps.c *** postgresql-7.1.3.orig/src/interfaces/odbc/gpps.c Sat Dec 8 19:18:08 2001 --- postgresql-7.1.3/src/interfaces/odbc/gpps.c Sat Dec 8 22:34:22 2001 *************** *** 43,48 **** --- 43,117 ---- #define FALSE ((BOOL)0) #endif + static FILE* open_ini_file(const char* name) + { + char buf[MAXPGPATH]; + FILE* fp = NULL; + size_t namelen, len; + const char* env; + struct passwd* pw; + + /* If it's an absolute path, try to open it */ + + if('/' == name[0]) { + fp = fopen(name, PG_BINARY_R); + if(fp) return fp; + } + + /* First look in $ODBCINI */ + + env = getenv("ODBCINI"); + if(env) { + fp = fopen(env, PG_BINARY_R); + if(fp) return fp; + } + + /* If the filename is too big for the buffer we fail now as + * nothing beyond this point is going to work */ + + namelen = strlen(name); + if(sizeof(buf) <= namelen) return NULL; + + /* Next try $HOME (note the period prefixed to the filename) */ + + env = getenv("HOME"); + if(env && env[0]) { + len = strlen(env) + namelen + 2; + if(sizeof(buf) > len) { + sprintf(buf, "%s/.%s", env, name); + fp = fopen(buf, PG_BINARY_R); + if(fp) return fp; + } + } + + /* Now try the home dir from /etc/passwd (again, note the period + * prefixed to the filename) */ + + pw = getpwuid(getuid()); + if(pw && pw->pw_dir && pw->pw_dir[0]) { + len = strlen(pw->pw_dir) + namelen + 2; + if(sizeof(buf) > len) { + sprintf(buf, "%s/.%s", pw->pw_dir, name); + fp = fopen(buf, PG_BINARY_R); + if(fp) return fp; + } + } + + /* Finally try the compile-time default */ + + #ifdef ODBCDIR + len = sizeof(ODBCDIR) + namelen + 1; + if(sizeof(buf) > len) { + sprintf(buf, ODBCDIR "/%s", name); + fp = fopen(buf, PG_BINARY_R); + if(fp) return fp; + } + #endif + + /* No luck */ + + return NULL; + } DWORD GetPrivateProfileString(char *theSection, /* section name */ *************** *** 56,63 **** char *theIniFileName) /* pathname of ini file to * search */ { - char buf[MAXPGPATH]; - char *ptr = 0; FILE *aFile = 0; size_t aLength; char aLine[2048]; --- 125,130 ---- *************** *** 68,115 **** size_t aReturnLength = 0; BOOL aSectionFound = FALSE; BOOL aKeyFound = FALSE; - int j = 0; - - j = strlen(theIniFileName) + 1; - ptr = (char *) getpwuid(getuid()); /* get user info */ - - if (ptr == NULL) - { - if (MAXPGPATH - 1 < j) - theIniFileName[MAXPGPATH - 1] = '\0'; - - sprintf(buf, "%s", theIniFileName); - } - ptr = ((struct passwd *) ptr)->pw_dir; /* get user home dir */ - if (ptr == NULL || *ptr == '\0') - ptr = "/home"; - - /* - * This doesn't make it so we find an ini file but allows normal - * processing to continue further on down. The likelihood is that the - * file won't be found and thus the default value will be returned. - */ - if (MAXPGPATH - 1 < strlen(ptr) + j) - { - if (MAXPGPATH - 1 < strlen(ptr)) - ptr[MAXPGPATH - 1] = '\0'; - else - theIniFileName[MAXPGPATH - 1 - strlen(ptr)] = '\0'; - } - - sprintf(buf, "%s/%s", ptr, theIniFileName); - - /* - * This code makes it so that a file in the users home dir overrides a - * the "default" file as passed in - */ - aFile = (FILE *) (buf ? fopen(buf, PG_BINARY_R) : NULL); - if (!aFile) - { - sprintf(buf, "%s", theIniFileName); - aFile = (FILE *) (buf ? fopen(buf, PG_BINARY_R) : NULL); - } aLength = (theDefault == NULL) ? 0 : strlen(theDefault); --- 135,142 ---- size_t aReturnLength = 0; BOOL aSectionFound = FALSE; BOOL aKeyFound = FALSE; + aFile = open_ini_file(theIniFileName); aLength = (theDefault == NULL) ? 0 : strlen(theDefault);