Skip to content

Commit 13a52c1

Browse files
committed
I installed postgres 7.1 with --enable-odbc. I then installed
tclodbc (http://sourceforge.net/projects/tclodbc) and libiodbc-2.50.3 (http://www.iodbc.org/dist/libiodbc-2.50.3.tar.gz). I could not get either to work... postgres would not find the global odbcinst.ini file. I traced this to src/interfaces/odbc/gpps.c -- here are the many things I think are wrong: Run tclodbc and do a ``database db <DSNname>'' where ``DSNname'' is one of the DSN's in /usr/local/etc/odbcinst.ini (or wherever the global ini file is installed.) The result is always the error message that ``one of server,port,database,etc. are missing''. Run libiodbc-2.50.3/samples/odbctest <DSNname>. The command fails to connect to the database and just exits. Dave Bodenstab
1 parent 55abc36 commit 13a52c1

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

src/interfaces/odbc/gpps.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <string.h>
3838
#include "misc.h"
3939
#include "gpps.h"
40+
#include "dlg_specific.h"
4041

4142
#ifndef TRUE
4243
#define TRUE ((BOOL)1)
@@ -46,6 +47,12 @@
4647
#endif
4748

4849

50+
/*
51+
* theIniFileName is searched for in:
52+
* $HOME/theIniFileName
53+
* theIniFileName
54+
* ODBCINST_INI
55+
*/
4956
DWORD
5057
GetPrivateProfileString(char *theSection, /* section name */
5158
char *theKey, /* search key name */
@@ -70,46 +77,38 @@ GetPrivateProfileString(char *theSection, /* section name */
7077
size_t aReturnLength = 0;
7178
BOOL aSectionFound = FALSE;
7279
BOOL aKeyFound = FALSE;
73-
int j = 0;
80+
size_t aReturnLength = 0;
81+
BOOL aSectionFound = FALSE;
82+
BOOL aKeyFound = FALSE;
7483

75-
j = strlen(theIniFileName) + 1;
7684
ptr = (char *) getpwuid(getuid()); /* get user info */
7785

78-
if (ptr == NULL)
79-
{
80-
if (MAXPGPATH - 1 < j)
81-
theIniFileName[MAXPGPATH - 1] = '\0';
82-
83-
sprintf(buf, "%s", theIniFileName);
84-
}
85-
ptr = ((struct passwd *) ptr)->pw_dir; /* get user home dir */
86-
if (ptr == NULL || *ptr == '\0')
86+
if (ptr == NULL || (((struct passwd *) ptr)->pw_dir) == NULL || *(((struct passwd *) ptr)->pw_dir) == '\0')
8787
ptr = "/home";
88+
else
89+
ptr = ((struct passwd *) ptr)->pw_dir; /* get user home dir */
8890

8991
/*
90-
* This doesn't make it so we find an ini file but allows normal
91-
* processing to continue further on down. The likelihood is that the
92-
* file won't be found and thus the default value will be returned.
92+
* If it can't be opened because the paths are too long, then
93+
* skip it, don't just truncate the path string... The truncated path
94+
* might accidently be an existing file. The default value will be
95+
* returned instead.
9396
*/
94-
if (MAXPGPATH - 1 < strlen(ptr) + j)
97+
if (MAXPGPATH - 1 >= strlen(ptr) + 1 + strlen(theIniFileName))
9598
{
96-
if (MAXPGPATH - 1 < strlen(ptr))
97-
ptr[MAXPGPATH - 1] = '\0';
98-
else
99-
theIniFileName[MAXPGPATH - 1 - strlen(ptr)] = '\0';
99+
sprintf(buf, "%s/%s", ptr, theIniFileName);
100+
aFile = (FILE *) fopen(buf, PG_BINARY_R);
100101
}
101102

102-
sprintf(buf, "%s/%s", ptr, theIniFileName);
103-
104103
/*
105104
* This code makes it so that a file in the users home dir overrides a
106105
* the "default" file as passed in
107106
*/
108-
aFile = (FILE *) (buf ? fopen(buf, PG_BINARY_R) : NULL);
109107
if (!aFile)
110108
{
111-
sprintf(buf, "%s", theIniFileName);
112-
aFile = (FILE *) (buf ? fopen(buf, PG_BINARY_R) : NULL);
109+
aFile = (FILE *) fopen(theIniFileName, PG_BINARY_R);
110+
if (!aFile)
111+
aFile = (FILE *) fopen(ODBCINST_INI, PG_BINARY_R);
113112
}
114113

115114
aLength = (theDefault == NULL) ? 0 : strlen(theDefault);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy