From 0484700cdaa55f35cd64953ae76fb42f76d17e90 Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Wed, 12 Jun 2002 02:27:44 +0000 Subject: [PATCH] 1) Fix a bug *double error message*. 2) Fix a bug *passowrd prompt in case of md5 authentication*. 3) Improve the DSN setup dialog. --- src/interfaces/odbc/connection.c | 31 +++++++++++++++++++------------ src/interfaces/odbc/connection.h | 2 +- src/interfaces/odbc/dlg_specific.h | 4 ++++ src/interfaces/odbc/dlg_wingui.c | 37 +++++++++++++++++++++++++++++++++++++ src/interfaces/odbc/drvconn.c | 8 +++++--- src/interfaces/odbc/psqlodbc.rc | 34 ++++++++++++++++++++++++++++++++-- src/interfaces/odbc/qresult.c | 21 +++++++++++++++------ src/interfaces/odbc/resource.h | 1 + src/interfaces/odbc/setup.c | 5 ++--- 9 files changed, 116 insertions(+), 27 deletions(-) diff --git a/src/interfaces/odbc/connection.c b/src/interfaces/odbc/connection.c index 9ae47052f7..c9b0c01c30 100644 --- a/src/interfaces/odbc/connection.c +++ b/src/interfaces/odbc/connection.c @@ -129,7 +129,7 @@ PGAPI_Connect( qlog("conn = %u, %s(DSN='%s', UID='%s', PWD='%s')\n", conn, func, ci->dsn, ci->username, ci->password); - if (CC_connect(conn, FALSE) <= 0) + if (CC_connect(conn, AUTH_REQ_OK, NULL) <= 0) { /* Error messages are filled in */ CC_log_error(func, "Error on CC_connect", conn); @@ -608,7 +608,7 @@ md5_auth_send(ConnectionClass *self, const char *salt) } char -CC_connect(ConnectionClass *self, char do_password) +CC_connect(ConnectionClass *self, char password_req, char *salt_para) { StartupPacket sp; StartupPacket6_2 sp62; @@ -627,7 +627,7 @@ CC_connect(ConnectionClass *self, char do_password) mylog("%s: entering...\n", func); - if (do_password) + if (password_req != AUTH_REQ_OK) sock = self->sock; /* already connected, just authenticate */ @@ -780,7 +780,7 @@ another_version_retry: do { - if (do_password) + if (password_req != AUTH_REQ_OK) beresp = 'R'; else { @@ -811,11 +811,13 @@ another_version_retry: return 0; case 'R': - if (do_password) + if (password_req != AUTH_REQ_OK) { - mylog("in 'R' do_password\n"); - areq = AUTH_REQ_PASSWORD; - do_password = FALSE; + mylog("in 'R' password_req=%s\n", ci->password); + areq = password_req; + if (salt_para) + memcpy(salt, salt_para, sizeof(salt)); + password_req = AUTH_REQ_OK; } else { @@ -823,7 +825,7 @@ another_version_retry: areq = SOCK_get_int(sock, 4); if (areq == AUTH_REQ_MD5) SOCK_get_n_char(sock, salt, 4); - if (areq == AUTH_REQ_CRYPT) + else if (areq == AUTH_REQ_CRYPT) SOCK_get_n_char(sock, salt, 2); mylog("areq = %d\n", areq); @@ -850,7 +852,7 @@ another_version_retry: { self->errornumber = CONNECTION_NEED_PASSWORD; self->errormsg = "A password is required for this connection."; - return -1; /* need password */ + return -areq; /* need password */ } mylog("past need password\n"); @@ -872,7 +874,9 @@ another_version_retry: { self->errornumber = CONNECTION_NEED_PASSWORD; self->errormsg = "A password is required for this connection."; - return -1; /* need password */ + if (salt_para) + memcpy(salt_para, salt, sizeof(salt)); + return -areq; /* need password */ } if (md5_auth_send(self, salt)) { @@ -1478,7 +1482,10 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi, UDWORD flag) self->errornumber = CONNECTION_COULD_NOT_RECEIVE; self->errormsg = QR_get_message(res); ReadyToReturn = TRUE; - retres = NULL; + if (PGRES_FATAL_ERROR == QR_get_status(res)) + retres = cmdres; + else + retres = NULL; break; } query_completed = TRUE; diff --git a/src/interfaces/odbc/connection.h b/src/interfaces/odbc/connection.h index 925efde3cd..5a26c29d78 100644 --- a/src/interfaces/odbc/connection.h +++ b/src/interfaces/odbc/connection.h @@ -328,7 +328,7 @@ char CC_begin(ConnectionClass *self); char CC_commit(ConnectionClass *self); char CC_abort(ConnectionClass *self); int CC_set_translation(ConnectionClass *self); -char CC_connect(ConnectionClass *self, char do_password); +char CC_connect(ConnectionClass *self, char password_req, char *salt); char CC_add_statement(ConnectionClass *self, StatementClass *stmt); char CC_remove_statement(ConnectionClass *self, StatementClass *stmt); char CC_get_error(ConnectionClass *self, int *number, char **message); diff --git a/src/interfaces/odbc/dlg_specific.h b/src/interfaces/odbc/dlg_specific.h index 9899bdac34..99005d3a33 100644 --- a/src/interfaces/odbc/dlg_specific.h +++ b/src/interfaces/odbc/dlg_specific.h @@ -174,6 +174,10 @@ int CALLBACK driver_optionsProc(HWND hdlg, UINT wMsg, WPARAM wParam, LPARAM lParam); +int CALLBACK global_optionsProc(HWND hdlg, + UINT wMsg, + WPARAM wParam, + LPARAM lParam); int CALLBACK ds_options1Proc(HWND hdlg, UINT wMsg, WPARAM wParam, diff --git a/src/interfaces/odbc/dlg_wingui.c b/src/interfaces/odbc/dlg_wingui.c index 27075d757e..88c2e9f4c4 100644 --- a/src/interfaces/odbc/dlg_wingui.c +++ b/src/interfaces/odbc/dlg_wingui.c @@ -267,6 +267,43 @@ driver_optionsProc(HWND hdlg, } int CALLBACK +global_optionsProc(HWND hdlg, + UINT wMsg, + WPARAM wParam, + LPARAM lParam) +{ + + switch (wMsg) + { + case WM_INITDIALOG: + CheckDlgButton(hdlg, DRV_COMMLOG, globals.commlog); +#ifndef Q_LOG + EnableWindow(GetDlgItem(hdlg, DRV_COMMLOG), FALSE); +#endif /* Q_LOG */ + CheckDlgButton(hdlg, DRV_DEBUG, globals.debug); +#ifndef MY_LOG + EnableWindow(GetDlgItem(hdlg, DRV_DEBUG), FALSE); +#endif /* MY_LOG */ + break; + + case WM_COMMAND: + switch (GET_WM_COMMAND_ID(wParam, lParam)) + { + case IDOK: + globals.commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG); + globals.debug = IsDlgButtonChecked(hdlg, DRV_DEBUG); + driver_options_update(hdlg, NULL, TRUE); + + case IDCANCEL: + EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK); + return TRUE; + } + } + + return FALSE; +} + +int CALLBACK ds_options1Proc(HWND hdlg, UINT wMsg, WPARAM wParam, diff --git a/src/interfaces/odbc/drvconn.c b/src/interfaces/odbc/drvconn.c index 1fb91550df..6c08376ac4 100644 --- a/src/interfaces/odbc/drvconn.c +++ b/src/interfaces/odbc/drvconn.c @@ -78,7 +78,8 @@ PGAPI_DriverConnect( char connStrIn[MAX_CONNECT_STRING]; char connStrOut[MAX_CONNECT_STRING]; int retval; - char password_required = FALSE; + char salt[5]; + char password_required = AUTH_REQ_OK; int len = 0; SWORD lenStrout; @@ -114,6 +115,7 @@ PGAPI_DriverConnect( getDSNdefaults(ci); /* initialize pg_version */ CC_initialize_pg_version(conn); + salt[0] = '\0'; #ifdef WIN32 dialog: @@ -173,7 +175,7 @@ dialog: } /* do the actual connect */ - retval = CC_connect(conn, password_required); + retval = CC_connect(conn, password_required, salt); if (retval < 0) { /* need a password */ if (fDriverCompletion == SQL_DRIVER_NOPROMPT) @@ -185,7 +187,7 @@ dialog: else { #ifdef WIN32 - password_required = TRUE; + password_required = -retval; goto dialog; #else return SQL_ERROR; /* until a better solution is found. */ diff --git a/src/interfaces/odbc/psqlodbc.rc b/src/interfaces/odbc/psqlodbc.rc index 054179e5fb..540ca4053c 100644 --- a/src/interfaces/odbc/psqlodbc.rc +++ b/src/interfaces/odbc/psqlodbc.rc @@ -79,7 +79,7 @@ BEGIN GROUPBOX "Options (Advanced):",IDC_OPTIONS,141,72,140,35, BS_CENTER PUSHBUTTON "DataSource",IDC_DATASOURCE,149,89,50,14 - PUSHBUTTON "Default",IDC_DRIVER,221,88,50,14 + PUSHBUTTON "Global",IDC_DRIVER,221,88,50,14 CTEXT "Please supply any missing information needed to connect.", DRV_MSG_LABEL,25,4,238,10 END @@ -195,6 +195,21 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,126,195,50,14 PUSHBUTTON "Apply",IDAPPLY,201,195,50,14 END + +DLG_OPTIONS_GLOBAL DIALOG DISCARDABLE 0, 0, 306, 90 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Global settings" +FONT 10, "Terminal" +BEGIN + CTEXT "Logging before establishing connections(the default for new DSNs also)", + DRV_MSG_LABEL,25,15,238,10 + CONTROL "Comm&Log (C:\\psqlodbc.log)",DRV_COMMLOG,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,13,30,120,10 + CONTROL "Mylog(C:\\mylog_xxxx.log Detailed debug output)",DRV_DEBUG,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,13,45,200,10 + DEFPUSHBUTTON "Save",IDOK,39,70,50,14,WS_GROUP + PUSHBUTTON "Cancel",IDCANCEL,104,70,50,15 +END #else DLG_CONFIG DIALOG DISCARDABLE 65, 43, 292, 116 STYLE DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_VISIBLE | WS_CAPTION | @@ -221,7 +236,7 @@ BEGIN GROUPBOX "Options (Advanced):",IDC_OPTIONS,140,74,140,35, BS_CENTER PUSHBUTTON "DataSource",IDC_DATASOURCE,160,90,50,14 - PUSHBUTTON "Default",IDC_DRIVER,220,90,50,14 + PUSHBUTTON "Global",IDC_DRIVER,220,90,50,14 CTEXT "Please supply any missing information needed to connect.", DRV_MSG_LABEL,36,5,220,15 END @@ -337,6 +352,21 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,126,196,50,14 PUSHBUTTON "Apply",IDAPPLY,201,196,50,14 END + +DLG_OPTIONS_GLOBAL DIALOG DISCARDABLE 0, 0, 306, 90 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Global settings" +FONT 8, "MS Sans Serif" +BEGIN + CTEXT "Logging before establishing connections(the default for new DSNs also)", + DRV_MSG_LABEL,25,15,238,10 + CONTROL "Comm&Log (C:\\psqlodbc.log)",DRV_COMMLOG,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,13,30,120,10 + CONTROL "Mylog(C:\\mylog_xxxx.log Detailed debug output)", + DRV_DEBUG,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,13,45,200,10 + DEFPUSHBUTTON "Save",IDOK,39,70,50,14,WS_GROUP + PUSHBUTTON "Cancel",IDCANCEL,104,70,50,15 +END #endif ///////////////////////////////////////////////////////////////////////////// diff --git a/src/interfaces/odbc/qresult.c b/src/interfaces/odbc/qresult.c index b10408207f..bb5f5ba246 100644 --- a/src/interfaces/odbc/qresult.c +++ b/src/interfaces/odbc/qresult.c @@ -456,6 +456,7 @@ QR_next_tuple(QResultClass *self) char fetch[128]; QueryInfo qi; ConnInfo *ci = NULL; + BOOL msg_truncated; UDWORD abort_opt; if (fetch_count < num_backend_rows) @@ -665,9 +666,12 @@ QR_next_tuple(QResultClass *self) } case 'E': /* Error */ - SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH); - QR_set_message(self, msgbuffer); - self->status = PGRES_FATAL_ERROR; + msg_truncated = SOCK_get_string(sock, msgbuffer, + ERROR_MSG_LENGTH); + + /* Remove a newline */ + if (msgbuffer[0] != '\0' && msgbuffer[strlen(msgbuffer) - 1] == '\n') + msgbuffer[strlen(msgbuffer) - 1] = '\0'; abort_opt = 0; if (!strncmp(msgbuffer, "FATAL", 5)) @@ -679,14 +683,19 @@ QR_next_tuple(QResultClass *self) mylog("ERROR from backend in next_tuple: '%s'\n", msgbuffer); qlog("ERROR from backend in next_tuple: '%s'\n", msgbuffer); + while (msg_truncated) + msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH); return FALSE; case 'N': /* Notice */ - SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH); - QR_set_message(self, msgbuffer); - self->status = PGRES_NONFATAL_ERROR; + msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH); + QR_set_notice(self, cmdbuffer); + if (QR_command_successful(self)) + QR_set_status(self, PGRES_NONFATAL_ERROR); qlog("NOTICE from backend in next_tuple: '%s'\n", msgbuffer); + while (msg_truncated) + msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH); continue; default: /* this should only happen if the backend diff --git a/src/interfaces/odbc/resource.h b/src/interfaces/odbc/resource.h index 570ba5c6e8..13c0a4ff75 100644 --- a/src/interfaces/odbc/resource.h +++ b/src/interfaces/odbc/resource.h @@ -6,6 +6,7 @@ #define IDS_MSGTITLE 2 #define DLG_OPTIONS_DRV 102 #define DLG_OPTIONS_DS 103 +#define DLG_OPTIONS_GLOBAL 104 #define IDC_DSNAME 400 #define IDC_DSNAMETEXT 401 #define IDC_DESC 404 diff --git a/src/interfaces/odbc/setup.c b/src/interfaces/odbc/setup.c index aefeb5d421..51173ec39e 100644 --- a/src/interfaces/odbc/setup.c +++ b/src/interfaces/odbc/setup.c @@ -290,9 +290,8 @@ ConfigDlgProc(HWND hdlg, case IDC_DRIVER: lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWL_USER); - - DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV), - hdlg, driver_optionsProc, (LPARAM) &lpsetupdlg->ci); + DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_GLOBAL), + hdlg, global_optionsProc, (LPARAM) &lpsetupdlg->ci); return TRUE; } -- 2.11.0