4
* Description: This module contains only routines related to
5
* implementing SQLDriverConnect.
9
* API functions: SQLDriverConnect
11
* Comments: See "notice.txt" for copyright and license information.
20
#include "connection.h"
23
#include <sys/types.h>
24
#include <sys/socket.h>
36
#include "pgapifunc.h"
45
#include "dlg_specific.h"
47
#define NULL_IF_NULL(a) (a ? a : "(NULL)")
49
static char * hide_password(const char *str)
53
if (!str) return NULL;
55
if (pwdp = strstr(outstr, "PWD="), !pwdp)
56
pwdp = strstr(outstr, "pwd=");
61
for (p=pwdp + 4; *p && *p != ';'; p++)
68
void dconn_get_connect_attributes(const UCHAR FAR * connect_string, ConnInfo *ci);
69
static void dconn_get_common_attributes(const UCHAR FAR * connect_string, ConnInfo *ci);
72
BOOL FAR PASCAL dconn_FDriverConnectProc(HWND hdlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
73
RETCODE dconn_DoDialog(HWND hwnd, ConnInfo *ci);
75
extern HINSTANCE NEAR s_hModule; /* Saved module handle. */
83
UCHAR FAR * szConnStrIn,
85
UCHAR FAR * szConnStrOut,
86
SWORD cbConnStrOutMax,
87
SWORD FAR * pcbConnStrOut,
88
UWORD fDriverCompletion)
90
CSTR func = "PGAPI_DriverConnect";
91
ConnectionClass *conn = (ConnectionClass *) hdbc;
95
RETCODE dialog_result;
98
char connStrIn[MAX_CONNECT_STRING];
99
char connStrOut[MAX_CONNECT_STRING];
102
char password_required = AUTH_REQ_OK;
107
mylog("%s: entering...\n", func);
111
CC_log_error(func, "", NULL);
112
return SQL_INVALID_HANDLE;
115
make_string(szConnStrIn, cbConnStrIn, connStrIn);
117
#ifdef FORCE_PASSWORD_DISPLAY
118
mylog("**** PGAPI_DriverConnect: fDriverCompletion=%d, connStrIn='%s'\n", fDriverCompletion, connStrIn);
119
qlog("conn=%u, PGAPI_DriverConnect( in)='%s', fDriverCompletion=%d\n", conn, connStrIn, fDriverCompletion);
121
if (get_qlog() || get_mylog())
123
char *hide_str = hide_password(connStrIn);
125
mylog("**** PGAPI_DriverConnect: fDriverCompletion=%d, connStrIn='%s'\n", fDriverCompletion, NULL_IF_NULL(hide_str));
126
qlog("conn=%u, PGAPI_DriverConnect( in)='%s', fDriverCompletion=%d\n", conn, NULL_IF_NULL(hide_str), fDriverCompletion);
130
#endif /* FORCE_PASSWORD_DISPLAY */
132
ci = &(conn->connInfo);
134
/* Parse the connect string and fill in conninfo for this hdbc. */
135
dconn_get_connect_attributes(connStrIn, ci);
138
* If the ConnInfo in the hdbc is missing anything, this function will
139
* fill them in from the registry (assuming of course there is a DSN
140
* given -- if not, it does nothing!)
142
getDSNinfo(ci, CONN_DONT_OVERWRITE);
143
dconn_get_common_attributes(connStrIn, ci);
144
logs_on_off(1, ci->drivers.debug, ci->drivers.commlog);
146
/* Fill in any default parameters if they are not there. */
148
/* initialize pg_version */
149
CC_initialize_pg_version(conn);
155
ci->focus_password = password_required;
157
switch (fDriverCompletion)
160
case SQL_DRIVER_PROMPT:
161
dialog_result = dconn_DoDialog(hwnd, ci);
162
if (dialog_result != SQL_SUCCESS)
163
return dialog_result;
166
case SQL_DRIVER_COMPLETE_REQUIRED:
170
case SQL_DRIVER_COMPLETE:
172
/* Password is not a required parameter. */
173
if (ci->username[0] == '\0' ||
174
ci->server[0] == '\0' ||
175
ci->database[0] == '\0' ||
176
ci->port[0] == '\0' ||
179
dialog_result = dconn_DoDialog(hwnd, ci);
180
if (dialog_result != SQL_SUCCESS)
181
return dialog_result;
185
case SQL_DRIVER_PROMPT:
186
case SQL_DRIVER_COMPLETE:
187
case SQL_DRIVER_COMPLETE_REQUIRED:
189
case SQL_DRIVER_NOPROMPT:
194
* Password is not a required parameter unless authentication asks for
195
* it. For now, I think it's better to just let the application ask
196
* over and over until a password is entered (the user can always hit
199
if (ci->username[0] == '\0' ||
200
ci->server[0] == '\0' ||
201
ci->database[0] == '\0' ||
204
/* (password_required && ci->password[0] == '\0')) */
206
return SQL_NO_DATA_FOUND;
209
/* do the actual connect */
210
retval = CC_connect(conn, password_required, salt);
212
{ /* need a password */
213
if (fDriverCompletion == SQL_DRIVER_NOPROMPT)
215
CC_log_error(func, "Need password but Driver_NoPrompt", conn);
216
return SQL_ERROR; /* need a password but not allowed to
222
password_required = -retval;
225
return SQL_ERROR; /* until a better solution is found. */
229
else if (retval == 0)
231
/* error msg filled in above */
232
CC_log_error(func, "Error from CC_Connect", conn);
237
* Create the Output Connection String
239
result = SQL_SUCCESS;
241
lenStrout = cbConnStrOutMax;
242
if (conn->ms_jet && lenStrout > 255)
244
makeConnectString(connStrOut, ci, lenStrout);
245
len = strlen(connStrOut);
250
* Return the completed string to the caller. The correct method
251
* is to only construct the connect string if a dialog was put up,
252
* otherwise, it should just copy the connection input string to
253
* the output. However, it seems ok to just always construct an
254
* output string. There are possible bad side effects on working
255
* applications (Access) by implementing the correct behavior,
258
strncpy_null(szConnStrOut, connStrOut, cbConnStrOutMax);
260
if (len >= cbConnStrOutMax)
264
for (clen = strlen(szConnStrOut) - 1; clen >= 0 && szConnStrOut[clen] != ';'; clen--)
265
szConnStrOut[clen] = '\0';
266
result = SQL_SUCCESS_WITH_INFO;
267
CC_set_error(conn, CONN_TRUNCATED, "The buffer was too small for the ConnStrOut.");
272
*pcbConnStrOut = len;
274
#ifdef FORCE_PASSWORD_DISPLAY
275
mylog("szConnStrOut = '%s' len=%d,%d\n", NULL_IF_NULL(szConnStrOut), len, cbConnStrOutMax);
276
qlog("conn=%u, PGAPI_DriverConnect(out)='%s'\n", conn, NULL_IF_NULL(szConnStrOut));
278
if (get_qlog() || get_mylog())
280
char *hide_str = hide_password(szConnStrOut);
282
mylog("szConnStrOut = '%s' len=%d,%d\n", NULL_IF_NULL(hide_str), len, cbConnStrOutMax);
283
qlog("conn=%u, PGAPI_DriverConnect(out)='%s'\n", conn, NULL_IF_NULL(hide_str));
287
#endif /* FORCE_PASSWORD_DISPLAY */
290
mylog("PGAPI_DriverConnect: returning %d\n", result);
297
dconn_DoDialog(HWND hwnd, ConnInfo *ci)
301
mylog("dconn_DoDialog: ci = %u\n", ci);
305
dialog_result = DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_CONFIG),
306
hwnd, dconn_FDriverConnectProc, (LPARAM) ci);
307
if (!dialog_result || (dialog_result == -1))
308
return SQL_NO_DATA_FOUND;
318
dconn_FDriverConnectProc(
330
ci = (ConnInfo *) lParam;
332
/* Change the caption for the setup dialog */
333
SetWindowText(hdlg, "PostgreSQL Connection");
335
LoadString(s_hModule, IDS_ADVANCE_CONNECTION, strbuf, sizeof(strbuf));
336
SetWindowText(GetDlgItem(hdlg, IDC_DATASOURCE), strbuf);
338
/* Hide the DSN and description fields */
339
ShowWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), SW_HIDE);
340
ShowWindow(GetDlgItem(hdlg, IDC_DSNAME), SW_HIDE);
341
ShowWindow(GetDlgItem(hdlg, IDC_DESCTEXT), SW_HIDE);
342
ShowWindow(GetDlgItem(hdlg, IDC_DESC), SW_HIDE);
343
ShowWindow(GetDlgItem(hdlg, IDC_DRIVER), SW_HIDE);
345
SetWindowLong(hdlg, DWL_USER, lParam); /* Save the ConnInfo for
347
SetDlgStuff(hdlg, ci);
349
if (ci->database[0] == '\0')
350
; /* default focus */
351
else if (ci->server[0] == '\0')
352
SetFocus(GetDlgItem(hdlg, IDC_SERVER));
353
else if (ci->port[0] == '\0')
354
SetFocus(GetDlgItem(hdlg, IDC_PORT));
355
else if (ci->username[0] == '\0')
356
SetFocus(GetDlgItem(hdlg, IDC_USER));
357
else if (ci->focus_password)
358
SetFocus(GetDlgItem(hdlg, IDC_PASSWORD));
362
switch (GET_WM_COMMAND_ID(wParam, lParam))
365
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
367
GetDlgStuff(hdlg, ci);
370
EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
374
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
375
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
376
hdlg, ds_options1Proc, (LPARAM) ci);
380
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
381
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
382
hdlg, driver_optionsProc, (LPARAM) ci);
393
dconn_get_connect_attributes(const UCHAR FAR * connect_string, ConnInfo *ci)
395
char *our_connect_string;
403
#endif /* HAVE_STRTOK_R */
405
CC_conninfo_init(ci);
407
our_connect_string = strdup(connect_string);
408
strtok_arg = our_connect_string;
410
#ifdef FORCE_PASSWORD_DISPLAY
411
mylog("our_connect_string = '%s'\n", our_connect_string);
415
char *hide_str = hide_password(our_connect_string);
417
mylog("our_connect_string = '%s'\n", hide_str);
420
#endif /* FORCE_PASSWORD_DISPLAY */
425
pair = strtok_r(strtok_arg, ";", &last);
427
pair = strtok(strtok_arg, ";");
428
#endif /* HAVE_STRTOK_R */
434
equals = strchr(pair, '=');
439
attribute = pair; /* ex. DSN */
440
value = equals + 1; /* ex. 'CEO co1' */
442
#ifndef FORCE_PASSWORD_DISPLAY
443
if (stricmp(attribute, INI_PASSWORD) == 0 ||
444
stricmp(attribute, "pwd") == 0)
445
mylog("attribute = '%s', value = 'xxxxx'\n", attribute);
447
#endif /* FORCE_PASSWORD_DISPLAY */
448
mylog("attribute = '%s', value = '%s'\n", attribute, value);
450
if (!attribute || !value)
453
/* Copy the appropriate value to the conninfo */
454
copyAttributes(ci, attribute, value);
458
free(our_connect_string);
462
dconn_get_common_attributes(const UCHAR FAR * connect_string, ConnInfo *ci)
464
char *our_connect_string;
472
#endif /* HAVE_STRTOK_R */
474
our_connect_string = strdup(connect_string);
475
strtok_arg = our_connect_string;
477
#ifdef FORCE_PASSWORD_DISPLAY
478
mylog("our_connect_string = '%s'\n", our_connect_string);
482
char *hide_str = hide_password(our_connect_string);
484
mylog("our_connect_string = '%s'\n", hide_str);
487
#endif /* FORCE_PASSWORD_DISPLAY */
492
pair = strtok_r(strtok_arg, ";", &last);
494
pair = strtok(strtok_arg, ";");
495
#endif /* HAVE_STRTOK_R */
501
equals = strchr(pair, '=');
506
attribute = pair; /* ex. DSN */
507
value = equals + 1; /* ex. 'CEO co1' */
509
#ifndef FORCE_PASSWORD_DISPLAY
510
if (stricmp(attribute, INI_PASSWORD) == 0 ||
511
stricmp(attribute, "pwd") == 0)
512
mylog("attribute = '%s', value = 'xxxxx'\n", attribute);
514
#endif /* FORCE_PASSWORD_DISPLAY */
515
mylog("attribute = '%s', value = '%s'\n", attribute, value);
517
if (!attribute || !value)
520
/* Copy the appropriate value to the conninfo */
521
copyCommonAttributes(ci, attribute, value);
525
free(our_connect_string);