BOOL TSetupDlg::IsPageValid (void) { switch (m_iCurPage) { case 0: /* DSN not blank */ if (!m_bFileDSN) { if (m_DSN.TextLength() == 0) return FALSE; /* DSN valid, except for file dsns */ if (!SQLValidDSN (m_DSN.Text ())) return FALSE; } /* Server not blank */ if (IsDlgComboEmpty (m_SERVER)) return FALSE; break; case 1: /* If using login to connect to db for settings, then not blank */ if (m_USEUID.Checked () && m_UID.TextLength() == 0) return FALSE; /* If using server certificate, then not blank */ if (m_USESERVERCERT.Checked () && m_SERVERCERT.TextLength() == 0) return FALSE; break; case 2: /* If not using default database, then not blank */ if (m_USEDEFAULTDB.Checked () && IsDlgComboEmpty (m_DEFAULTDB)) return FALSE; /* If not using default charset, then not blank */ if (m_USEDEFAULTCS.Checked () && IsDlgComboEmpty (m_DEFAULTCS)) return FALSE; /* If not using default isolation level, then not blank */ if (m_USEDEFAULTIL.Checked () && IsDlgComboEmpty (m_DEFAULTIL)) return FALSE; break; default: break; } return TRUE; }
BOOL INSTAPI SQLValidDSNW(LPCWSTR lpszDSN) { char *dsn; BOOL ret; dsn = _single_string_alloc_and_copy( lpszDSN ); ret = SQLValidDSN( dsn ); free( dsn ); return ret; }
/** * Go looking for trouble. Return NULL if the info is okay, or an error message * if something needs to change. */ static const char * validate(DSNINFO * di) { if (!SQLValidDSN(tds_dstr_cstr(&di->dsn))) return "Invalid DSN"; if (!IS_TDS42(di->login) && !IS_TDS46(di->login) && !IS_TDS50(di->login) && !IS_TDS7_PLUS(di->login)) return "Bad Protocol version"; if (tds_dstr_isempty(&di->login->server_name)) return "Address is required"; if (di->login->port < 1 || di->login->port > 65535) return "Bad port - Try 1433 or 4000"; return NULL; }
my_bool DSNDialog(HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR lpszAttributes, MADB_Dsn *Dsn) { MSG msg; BOOL ret; char *DsnName= NULL; my_bool DsnExists= FALSE; if (Dsn->isPrompt < 0 || Dsn->isPrompt > MAODBC_PROMPT_REQUIRED) { Dsn->isPrompt= MAODBC_CONFIG; } EffectiveDisabledPages= DisabledPages[Dsn->isPrompt]; EffectiveDisabledControls= DisabledControls[Dsn->isPrompt]; if (lpszAttributes) DsnName= strchr((char *)lpszAttributes, '='); if (lpszDriver) MADB_DriverGet((char *)lpszDriver); if (DsnName) { ++DsnName; /* In case of prompting we are supposed to show dialog even DSN name is incorrect */ if (!Dsn->isPrompt && !SQLValidDSN(DsnName)) { if (hwndParent) MessageBox(hwndParent, "Validation of data source name failed", "Error", MB_ICONERROR | MB_OK); return FALSE; } } if (!DsnName && Dsn && Dsn->DSNName) { DsnName= Dsn->DSNName; } else if (DsnName && Dsn) { /* Need to free current value in Dsn->DSNName */ MADB_SUBSTITUTE(Dsn->DSNName, _strdup(DsnName)); } /* Even if DsnName invalid(in case of prompt) - we should not have problem */ DsnExists= MADB_DSN_Exists(DsnName); InitCommonControls(); if (lpszDriver) Dsn->Driver= _strdup(lpszDriver); SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &Environment); SQLSetEnvAttr(Environment, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0); if (fRequest == ODBC_ADD_DSN) { if (DsnExists && hwndParent) { if (MessageBox(hwndParent, "Data source name already exists, do you want to replace it?", "Question", MB_ICONQUESTION | MB_YESNO) != IDYES) return FALSE; } Dsn->IsTcpIp= 1; } else { /* i.e. not a prompt */ if (Dsn->isPrompt == MAODBC_CONFIG) { if (!DsnExists) { MessageBox(0, "Data source name not found", "Error", MB_ICONERROR | MB_OK); return FALSE; } else if (!MADB_ReadDSN(Dsn, (char *)lpszAttributes, TRUE)) { SQLPostInstallerError(ODBC_ERROR_INVALID_DSN, Dsn->ErrorMsg); return FALSE; } } } notCanceled= TRUE; hwndMain= CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), 0, DialogProc, 0); SetWindowLongPtr(hwndMain, DWLP_USER, (LONG)Dsn); /* Setting first not disabled page */ CurrentPage= -1; SetPage(hwndMain, 1); Edit_SetReadOnly(GetDlgItem(hwndTab[0], txtDsnName), (hwndParent && DsnName && fRequest == ODBC_ADD_DSN) ? TRUE : FALSE); SetDialogFields(); CenterWindow(hwndMain); ShowWindow(hwndMain, SW_SHOW); while((ret = GetMessage(&msg, 0, 0, 0)) != 0) { if(ret == -1) break; if(!IsDialogMessage(hwndTab[CurrentPage], &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } SQLFreeHandle(SQL_HANDLE_ENV, Environment); return notCanceled; }
BOOL SQLWriteDSNToIni( LPCSTR pszDSN, LPCSTR pszDriver ) { HINI hIni; char szFileName[ODBC_FILENAME_MAX+1]; SQLRemoveDSNFromIni( pszDSN ); /* SANITY CHECKS */ if ( pszDSN == NULL ) { inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" ); return FALSE; } if ( pszDSN[0] == '\0' ) { inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" ); return FALSE; } if ( (strcasecmp( pszDSN, "DEFAULT" ) != 0 ) && (pszDriver == NULL ) ) { inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_NAME, "" ); return FALSE; } if ( (strcasecmp( pszDSN, "DEFAULT" ) != 0 ) && (pszDriver[0] == '\0') ) { inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_NAME, "" ); return FALSE; } if ( SQLValidDSN( pszDSN ) == FALSE ) { inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_DSN, "" ); return FALSE; } /* OK */ if ( _odbcinst_ConfigModeINI( szFileName ) == FALSE ) { inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_REQUEST_FAILED, "" ); return FALSE; } #ifdef __OS2__ if ( iniOpen( &hIni, szFileName, "#;", '[', ']', '=', TRUE, 1L ) != INI_SUCCESS ) #else if ( iniOpen( &hIni, szFileName, "#;", '[', ']', '=', TRUE ) != INI_SUCCESS ) #endif { inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_REQUEST_FAILED, "" ); return FALSE; } iniObjectInsert( hIni, (char *)pszDSN ); if ( pszDriver != NULL ) { iniPropertyInsert( hIni, "Driver", (char *)pszDriver ); } if ( iniCommit( hIni ) != INI_SUCCESS ) { iniClose( hIni ); inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_REQUEST_FAILED, "" ); return FALSE; } iniClose( hIni ); return TRUE; }
/* {{{ MADB_SaveDSN */ my_bool MADB_SaveDSN(MADB_Dsn *Dsn) { int i= 1; char Value[32]; my_bool ret; DWORD ErrNum; if (!SQLValidDSN(Dsn->DSNName)) { strcpy_s(Dsn->ErrorMsg, SQL_MAX_MESSAGE_LENGTH, "Invalid Data Source Name"); return FALSE; } if (!SQLRemoveDSNFromIni(Dsn->DSNName)) { SQLInstallerError(1,&ErrNum, Dsn->ErrorMsg, SQL_MAX_MESSAGE_LENGTH, NULL); return FALSE; } if (!SQLWriteDSNToIni(Dsn->DSNName, Dsn->Driver)) { SQLInstallerError(1,&ErrNum, Dsn->ErrorMsg, SQL_MAX_MESSAGE_LENGTH, NULL); return FALSE; } while(DsnKeys[i].DsnKey) { ret= TRUE; switch(DsnKeys[i].Type){ case DSN_TYPE_BOOL: ret= SQLWritePrivateProfileString(Dsn->DSNName, DsnKeys[i].DsnKey, *(my_bool *)((char *)Dsn + DsnKeys[i].DsnOffset) ? "1" : "0", "ODBC.INI"); break; case DSN_TYPE_INT: { my_snprintf(Value ,32, "%d", *(int *)((char *)Dsn + DsnKeys[i].DsnOffset)); ret= SQLWritePrivateProfileString(Dsn->DSNName, DsnKeys[i].DsnKey, Value, "ODBC.INI"); } break; case DSN_TYPE_STRING: case DSN_TYPE_COMBO: { char *Val= *(char **)((char *)Dsn + DsnKeys[i].DsnOffset); if (Val && Val[0]) ret= SQLWritePrivateProfileString(Dsn->DSNName, DsnKeys[i].DsnKey, Val, "ODBC.INI"); } break; } if (!ret) { SQLInstallerError(1,&ErrNum, Dsn->ErrorMsg, SQL_MAX_MESSAGE_LENGTH, NULL); return FALSE; } i++; } /* Save Options */ my_snprintf(Value ,32, "%d", Dsn->Options); if (!(ret= SQLWritePrivateProfileString(Dsn->DSNName, "OPTIONS", Value, "ODBC.INI"))) { SQLInstallerError(1,&ErrNum, Dsn->ErrorMsg, SQL_MAX_MESSAGE_LENGTH, NULL); return FALSE; } return TRUE; }