Пример #1
0
static void test_SQLConfigMode(void)
{
    BOOL bool_ret;
    DWORD error_code;
    RETCODE sql_ret;
    UWORD config_mode;
    int i;

    ok(SQLGetConfigMode(NULL), "SQLGetConfigMode(NULL) should succeed\n");

    bool_ret = SQLGetConfigMode(&config_mode);
    ok(bool_ret && config_mode == ODBC_BOTH_DSN, "Failed to get the initial SQLGetConfigMode or it was not both\n");

    /* try to set invalid mode */
    bool_ret = SQLSetConfigMode(ODBC_SYSTEM_DSN+1);
    sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
    ok(!bool_ret && sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_PARAM_SEQUENCE, "SQLSetConfigMode with invalid argument did not fail correctly\n");

    for (i = ODBC_SYSTEM_DSN; i >= ODBC_BOTH_DSN; --i)
    {
        ok(SQLSetConfigMode((UWORD)i), "SQLSetConfigMode Failed to set config mode\n");
        bool_ret = SQLGetConfigMode(&config_mode);
        ok(bool_ret && config_mode == i, "Failed to confirm SQLSetConfigMode.\n");
    }
    /* And that leaves it correctly on BOTH */
}
Пример #2
0
void COdbcDS::UpdateDS(const char* pNewDriverName, int iType, CDSList& DSList)
{
	int count = DSList.getCount();
	int length = sizeof(PRIV_PROFILE) / MAXKEYLEN;
	char* DSName = NULL;
	char* DSAttVal = NULL;

	// Set the config mode to the desired type.
	UWORD oldMode, newMode;

	if (iType == COdbcDS::DS_TYPE_SYS)
	{
		newMode = ODBC_SYSTEM_DSN;
	}
	else
	{
		newMode = ODBC_USER_DSN;
	}

	SQLGetConfigMode(&oldMode);
	SQLSetConfigMode(newMode);

	for (int i = 0; i < count; i++)
	{
		DSName = DSList.getAt(i);

		// Remove the old data sources
		SQLRemoveDSNFromIni(DSName);

		// Add the new data source
		if (TRUE != SQLWriteDSNToIni(DSName, pNewDriverName))
		{
			// Restore old config mode.
			SQLSetConfigMode(oldMode);
			throw -1;
		}

		// Configure the new data source using previous information.
		for (int index = 0; index < length; index++)
		{
			DSAttVal = DSList.getAttribValue(i, PRIV_PROFILE[index]);

			if (TRUE != SQLWritePrivateProfileString(DSName,
							PRIV_PROFILE[index], DSAttVal, ODBC_INI))
			{
				// Restore old config mode.
				SQLSetConfigMode(oldMode);
				throw -2;
			}

			delete [] DSAttVal;
		}

		delete [] DSName;
	}

	// Restore old config mode.
	SQLSetConfigMode(oldMode);
}
Пример #3
0
void COdbcDS::RetrieveMxDSInfo(int iType, CDSList& DSList)
{
	TCHAR Buff[255];
	char* DSName = NULL;
	int count = DSList.getCount();
	int length = sizeof(PRIV_PROFILE) / MAXKEYLEN;

	// Set the config mode to the desired type.
	UWORD oldMode, newMode;

	if (iType == COdbcDS::DS_TYPE_SYS)
	{
		newMode = ODBC_SYSTEM_DSN;
	}
	else
	{
		newMode = ODBC_USER_DSN;
	}

	SQLGetConfigMode(&oldMode);
	SQLSetConfigMode(newMode);

	for (int i = 0; i < count; i++)
	{
		DSName = DSList.getAt(i);

		for(int index = 0; index < length; index++)
		{

			// Retrieve the private profile strings.
			SQLGetPrivateProfileString(DSName, PRIV_PROFILE[index],
				"", Buff, sizeof(Buff), ODBC_INI);
			DSList.addAttrib(i, PRIV_PROFILE[index], Buff);
		}

		delete [] DSName;
	}

	// Restore old config mode.
	SQLSetConfigMode(oldMode);
}
Пример #4
0
/*! 
 * \brief   Save Data Source Name.
 *
 *          Call this to save User, System and File DSN's based upon a property list.
 * 
 * \param   pwidgetParent   Input. Widget to use as parent for messages. Null is ok.
 * \param   hFirstProperty  Input. First property in NULL terminated property list.
 * \param   nType           Input. Type of DSN.
 * \param   stringIni       Input. Default is QString::null.
 *
 *                          \li User and System DSN. This can be a QString::null to use 
 *                          default location or it can be a fully qualified path and name.
 *                          \li File DSN. This can be a QString::null to use default 
 *                          location or it can be an abs directory. In either case the file
 *                          name itself will be derived from the Name property.
 * 
 * \return  bool
 * \retval  true    Hey - it worked :)
 * \retval  false   Call failed for some reason. Error message(s) is shown in message dialog.
 */
bool CODBCInst::saveDataSourceName( QWidget *pwidgetParent, HODBCINSTPROPERTY hFirstProperty, CDSNWizardData::Type nType, const QString &stringIni )
{
    // sanity checks...
    if ( !hFirstProperty )
    {
        QMessageBox::critical( pwidgetParent, QObject::tr( "ODBC Administrator" ),  QObject::tr( "Programmer error: Uninitialized property list." ) );
        return false;
    }
    if ( (QString( hFirstProperty->szValue )).simplified().isEmpty() )
    {
        QMessageBox::critical( pwidgetParent, QObject::tr( "ODBC Administrator" ),  QObject::tr( "Missing 'Name' property value." ) );
        return false;
    }

    // init
    UWORD   nConfigMode     = ODBC_BOTH_DSN;
    bool    bReturn         = false;
    QString stringFileName  = stringIni;

    switch ( nType )
    {
        case CDSNWizardData::TypeUser:
            SQLGetConfigMode( &nConfigMode );
            SQLSetConfigMode( ODBC_USER_DSN );
            if ( stringFileName.isEmpty() ) stringFileName = "odbc.ini";
            break;
        case CDSNWizardData::TypeSystem:
            SQLGetConfigMode( &nConfigMode );
            SQLSetConfigMode( ODBC_SYSTEM_DSN );
            if ( stringFileName.isEmpty() ) stringFileName = "odbc.ini";
            break;
        case CDSNWizardData::TypeFile:
            // should we calc the dir and file name (do not allow the special purpose names)...
            if ( stringFileName.isEmpty() || stringFileName.at( 0 ) != QChar( '/' ) )
            {
                char szDirectory[FILENAME_MAX];

                szDirectory[0] = '\0';
                _odbcinst_FileINI( szDirectory );
                stringFileName = QString( "%1/%2.dsn" ).arg( szDirectory ).arg( hFirstProperty->szValue );
            }
            else if ( stringFileName.at( 0 ) == QChar( '/' ) )
                stringFileName = QString( "%1/%2.dsn" ).arg( stringFileName ).arg( hFirstProperty->szValue );
            else
            {
                QMessageBox::critical( pwidgetParent, QObject::tr( "ODBC Administrator" ),  QObject::tr( "File DSN directory expected but seems to be a name or file name." ) );
                return false;
            }
            break;
        default:
            QMessageBox::critical( pwidgetParent, QObject::tr( "ODBC Administrator" ),  QObject::tr( "Unhandled Data Source Name Type" ) );
            return false;
    }

    // save...
    if ( nType == CDSNWizardData::TypeFile )
    {
        // create the file with a section called "ODBC"...
        if ( !SQLWriteFileDSN( stringFileName.toAscii().data(), "ODBC", NULL, NULL ) )
        {
            showErrors( 0, QString( "Could not write to (%1)" ).arg( stringFileName ) );
            goto CODBCInstExit1;
        }
        // add all of the properties...
        for ( HODBCINSTPROPERTY hCurProperty = hFirstProperty->pNext; hCurProperty != NULL; hCurProperty = hCurProperty->pNext )
        {
            if ( !SQLWriteFileDSN( stringFileName.toAscii().data(), "ODBC", hCurProperty->szName, hCurProperty->szValue ) )
            {
                showErrors( 0, QString( "Could not write to (%1)" ).arg( stringFileName ) );
                goto CODBCInstExit1;
            }
        }
    }
    else
    {
        // create a section called using Name property (always 1st property)...
        if ( SQLWritePrivateProfileString( hFirstProperty->szValue, NULL, NULL, stringFileName.toAscii().data() ) == FALSE )
        {
            showErrors( pwidgetParent, QString( QObject::tr( "Could not write to (%1). You may need additional system privileges." ) ).arg( stringFileName ) );
            goto CODBCInstExit1;
        }
        // add all of the properties...
        for ( HODBCINSTPROPERTY hCurProperty = hFirstProperty->pNext; hCurProperty != NULL; hCurProperty = hCurProperty->pNext )
        {
            SQLWritePrivateProfileString( hFirstProperty->szValue, hCurProperty->szName, hCurProperty->szValue, stringFileName.toAscii().data() );
        }
    }

    bReturn = true;

    // fini
CODBCInstExit1:
    if ( nType != CDSNWizardData::TypeFile )
        SQLSetConfigMode( nConfigMode );

    return bReturn;
}
Пример #5
0
void InitializeTrace()
{

	//Read Trace Flag and TraceDLL
	char	szTraceFlags[100];
	char	szTraceDll[_MAX_PATH+1];

	UWORD   wConfigMode;

	if (g_hTraceDLL != NULL && GetModuleHandle(TRACE_DLL_NAME) == g_hTraceDLL){
		if(fpTraceProcessEntry)
			pdwGlobalTraceVariable = fpTraceProcessEntry();
		return;
	}
	
	SQLGetConfigMode( &wConfigMode);
	SQLSetConfigMode( ODBC_USER_DSN);
	SQLGetPrivateProfileString(szODBC, 
								szTraceDllKey, 
								szDefaultTraceDll,
								szTraceDll, 
								sizeof(szTraceDll), 
								szODBCIni);
//
// ODBC DM 3.52 works only with HKEY_CURRENT_USER
//
/*
	if ((g_hTraceDLL = GetModuleHandle(szTraceDll)) == NULL)
	{
		SQLSetConfigMode( ODBC_SYSTEM_DSN);
		SQLGetPrivateProfileString(szODBC, 
									szTraceDllKey, 
									szDefaultTraceDll,
									szTraceDll, 
									sizeof(szTraceDll), 
									szODBCIni);
		if ((g_hTraceDLL = GetModuleHandle(szTraceDll)) == NULL)
		{
			SQLSetConfigMode( wConfigMode);
			return;
		}
	}
*/
	SQLGetPrivateProfileString(szODBC, 
								szTraceFlagsKey, 
								szDefaultTraceFlags,
								szTraceFlags, 
								sizeof(szTraceFlags), 
								szODBCIni);
		
	SQLSetConfigMode( wConfigMode);

	gTraceFlags = atol(szTraceFlags);

	if ((g_hTraceDLL = GetModuleHandle(TRACE_DLL_NAME)) != NULL)
	{
		fpTraceProcessEntry = (FPTraceProcessEntry) GetProcAddress(g_hTraceDLL, "TraceProcessEntry");
		fpTraceDebugOut = (FPTraceDebugOut) GetProcAddress(g_hTraceDLL, "TraceDebugOut");
		fpTracePrintMarker = (FPTracePrintMarker) GetProcAddress(g_hTraceDLL, "TracePrintMarker");
		fpTraceFirstEntry = (FPTraceFirstEntry) GetProcAddress(g_hTraceDLL, "TraceFirstEntry");
		fpTraceReturn = (FPTraceReturn) GetProcAddress(g_hTraceDLL, "TraceReturn");
		fpTraceSQLAllocHandle = (FPTraceSQLAllocHandle) GetProcAddress(g_hTraceDLL, "TraceSQLAllocHandle");
		fpTraceSQLBindCol = (FPTraceSQLBindCol) GetProcAddress(g_hTraceDLL, "TraceSQLBindCol");
		fpTraceSQLBindParameter = (FPTraceSQLBindParameter) GetProcAddress(g_hTraceDLL, "TraceSQLBindParameter");
		fpTraceSQLCancel = (FPTraceSQLCancel) GetProcAddress(g_hTraceDLL, "TraceSQLCancel");
		fpTraceSQLCloseCursor = (FPTraceSQLCloseCursor) GetProcAddress(g_hTraceDLL, "TraceSQLCloseCursor");
		fpTraceSQLCopyDesc = (FPTraceSQLCopyDesc) GetProcAddress(g_hTraceDLL, "TraceSQLCopyDesc");
		fpTraceSQLDescribeParam = (FPTraceSQLDescribeParam) GetProcAddress(g_hTraceDLL, "TraceSQLDescribeParam");
		fpTraceSQLDisconnect = (FPTraceSQLDisconnect) GetProcAddress(g_hTraceDLL, "TraceSQLDisconnect");
		fpTraceSQLEndTran = (FPTraceSQLEndTran) GetProcAddress(g_hTraceDLL, "TraceSQLEndTran");
		fpTraceSQLExecute = (FPTraceSQLExecute) GetProcAddress(g_hTraceDLL, "TraceSQLExecute");
		fpTraceSQLExtendedFetch = (FPTraceSQLExtendedFetch) GetProcAddress(g_hTraceDLL, "TraceSQLExtendedFetch");
		fpTraceSQLFetch = (FPTraceSQLFetch) GetProcAddress(g_hTraceDLL, "TraceSQLFetch");
		fpTraceSQLFetchScroll = (FPTraceSQLFetchScroll) GetProcAddress(g_hTraceDLL, "TraceSQLFetchScroll");
		fpTraceSQLFreeHandle = (FPTraceSQLFreeHandle) GetProcAddress(g_hTraceDLL, "TraceSQLFreeHandle");
		fpTraceSQLFreeStmt = (FPTraceSQLFreeStmt) GetProcAddress(g_hTraceDLL, "TraceSQLFreeStmt");
		fpTraceSQLGetData = (FPTraceSQLGetData) GetProcAddress(g_hTraceDLL, "TraceSQLGetData");
		fpTraceSQLGetEnvAttr = (FPTraceSQLGetEnvAttr) GetProcAddress(g_hTraceDLL, "TraceSQLGetEnvAttr");
		fpTraceSQLGetTypeInfo = (FPTraceSQLGetTypeInfo) GetProcAddress(g_hTraceDLL, "TraceSQLGetTypeInfo");
		fpTraceSQLMoreResults = (FPTraceSQLMoreResults) GetProcAddress(g_hTraceDLL, "TraceSQLMoreResults");
		fpTraceSQLNumParams = (FPTraceSQLNumParams) GetProcAddress(g_hTraceDLL, "TraceSQLNumParams");
		fpTraceSQLNumResultCols = (FPTraceSQLNumResultCols) GetProcAddress(g_hTraceDLL, "TraceSQLNumResultCols");
		fpTraceSQLParamData = (FPTraceSQLParamData) GetProcAddress(g_hTraceDLL, "TraceSQLParamData");
		fpTraceSQLPutData = (FPTraceSQLPutData) GetProcAddress(g_hTraceDLL, "TraceSQLPutData");
		fpTraceSQLRowCount = (FPTraceSQLRowCount) GetProcAddress(g_hTraceDLL, "TraceSQLRowCount");
		fpTraceSQLSetEnvAttr = (FPTraceSQLSetEnvAttr) GetProcAddress(g_hTraceDLL, "TraceSQLSetEnvAttr");
		fpTraceSQLSetPos = (FPTraceSQLSetPos) GetProcAddress(g_hTraceDLL, "TraceSQLSetPos");
		fpTraceASVersion = (VERSION_def**) GetProcAddress(g_hTraceDLL, "ASVersion");
		fpTraceSrvrVersion = (VERSION_def**) GetProcAddress(g_hTraceDLL, "SrvrVersion");
		fpTraceSqlVersion = (VERSION_def**) GetProcAddress(g_hTraceDLL, "SqlVersion");
		fpTraceTransportIn = (FPTraceTransportIn) GetProcAddress(g_hTraceDLL, "TraceTransportIn");
		fpTraceTransportOut = (FPTraceTransportOut) GetProcAddress(g_hTraceDLL, "TraceTransportOut");
		fpTraceSQLSetDescRec = (FPTraceSQLSetDescRec) GetProcAddress(g_hTraceDLL, "TraceSQLSetDescRec");
		//Unicode functions
		fpTraceSQLGetDiagRecW = (FPTraceSQLGetDiagRecW) GetProcAddress(g_hTraceDLL, "TraceSQLGetDiagRecW");
		fpTraceSQLGetDiagFieldW = (FPTraceSQLGetDiagFieldW) GetProcAddress(g_hTraceDLL, "TraceSQLGetDiagFieldW");
		fpTraceSQLConnectW = (FPTraceSQLConnectW) GetProcAddress(g_hTraceDLL, "TraceSQLConnectW");
		fpTraceSQLSetConnectAttrW = (FPTraceSQLSetConnectAttrW) GetProcAddress(g_hTraceDLL, "TraceSQLSetConnectAttrW");
		fpTraceSQLGetConnectAttrW = (FPTraceSQLGetConnectAttrW) GetProcAddress(g_hTraceDLL, "TraceSQLGetConnectAttrW");
		fpTraceSQLSetStmtAttrW = (FPTraceSQLSetStmtAttrW) GetProcAddress(g_hTraceDLL, "TraceSQLSetStmtAttrW");
		fpTraceSQLGetStmtAttrW = (FPTraceSQLGetStmtAttrW) GetProcAddress(g_hTraceDLL, "TraceSQLGetStmtAttrW");
		fpTraceSQLGetInfoW = (FPTraceSQLGetInfoW) GetProcAddress(g_hTraceDLL, "TraceSQLGetInfoW");
		fpTraceSQLSetDescFieldW = (FPTraceSQLSetDescFieldW) GetProcAddress(g_hTraceDLL, "TraceSQLSetDescFieldW");
		fpTraceSQLGetDescFieldW = (FPTraceSQLGetDescFieldW) GetProcAddress(g_hTraceDLL, "TraceSQLGetDescFieldW");
		fpTraceSQLGetDescRecW = (FPTraceSQLGetDescRecW) GetProcAddress(g_hTraceDLL, "TraceSQLGetDescRecW");
		fpTraceSQLBrowseConnectW = (FPTraceSQLBrowseConnectW) GetProcAddress(g_hTraceDLL, "TraceSQLBrowseConnectW");
		fpTraceSQLDriverConnectW = (FPTraceSQLDriverConnectW) GetProcAddress(g_hTraceDLL, "TraceSQLDriverConnectW");
		fpTraceSQLPrepareW = (FPTraceSQLPrepareW) GetProcAddress(g_hTraceDLL, "TraceSQLPrepareW");
		fpTraceSQLExecDirectW = (FPTraceSQLExecDirectW) GetProcAddress(g_hTraceDLL, "TraceSQLExecDirectW");
		fpTraceSQLDescribeColW = (FPTraceSQLDescribeColW) GetProcAddress(g_hTraceDLL, "TraceSQLDescribeColW");
		fpTraceSQLTablesW = (FPTraceSQLTablesW) GetProcAddress(g_hTraceDLL, "TraceSQLTablesW");
		fpTraceSQLColumnsW = (FPTraceSQLColumnsW) GetProcAddress(g_hTraceDLL, "TraceSQLColumnsW");
		fpTraceSQLSpecialColumnsW = (FPTraceSQLSpecialColumnsW) GetProcAddress(g_hTraceDLL, "TraceSQLSpecialColumnsW");
		fpTraceSQLPrimaryKeysW = (FPTraceSQLPrimaryKeysW) GetProcAddress(g_hTraceDLL, "TraceSQLPrimaryKeysW");
		fpTraceSQLStatisticsW = (FPTraceSQLStatisticsW) GetProcAddress(g_hTraceDLL, "TraceSQLStatisticsW");
		fpTraceSQLGetCursorNameW = (FPTraceSQLGetCursorNameW) GetProcAddress(g_hTraceDLL, "TraceSQLGetCursorNameW");
		fpTraceSQLSetCursorNameW = (FPTraceSQLSetCursorNameW) GetProcAddress(g_hTraceDLL, "TraceSQLSetCursorNameW");
		fpTraceSQLNativeSqlW = (FPTraceSQLNativeSqlW) GetProcAddress(g_hTraceDLL, "TraceSQLNativeSqlW");
		fpTraceSQLColAttributeW = (FPTraceSQLColAttributeW) GetProcAddress(g_hTraceDLL, "TraceSQLColAttributeW");
		fpTraceSQLProceduresW = (FPTraceSQLProceduresW) GetProcAddress(g_hTraceDLL, "TraceSQLProceduresW");
		fpTraceSQLProcedureColumnsW = (FPTraceSQLProcedureColumnsW) GetProcAddress(g_hTraceDLL, "TraceSQLProcedureColumnsW");
		fpTraceSQLColumnPrivilegesW = (FPTraceSQLColumnPrivilegesW) GetProcAddress(g_hTraceDLL, "TraceSQLColumnPrivilegesW");
		fpTraceSQLTablePrivilegesW = (FPTraceSQLTablePrivilegesW) GetProcAddress(g_hTraceDLL, "TraceSQLTablePrivilegesW");
		fpTraceSQLForeignKeysW = (FPTraceSQLForeignKeysW) GetProcAddress(g_hTraceDLL, "TraceSQLForeignKeysW");
		




	}
	if(fpTraceProcessEntry)
		pdwGlobalTraceVariable = fpTraceProcessEntry();
}
Пример #6
0
BOOL INSTAPI
ConfigDSN (
    HWND	  hwndParent,
    WORD	  fRequest,
    LPCSTR	  lpszDriver,
    LPCSTR	  lpszAttributes)
{
  char *dsn = NULL, *connstr = NULL, *curr, *cour = NULL;
  char dsnread[4096] = { 0 };
  char prov[4096] = { 0 };
  int driver_type = -1, flags = 0;
  BOOL retcode = FALSE;
  UWORD confMode = ODBC_USER_DSN;

  /* Map the request User/System */
  if (fRequest < ODBC_ADD_DSN || fRequest > ODBC_REMOVE_DSN)
    {
      SQLPostInstallerError (ODBC_ERROR_INVALID_REQUEST_TYPE, NULL);
      goto done;
    }

  if (!lpszDriver || !STRLEN (lpszDriver))
    {
      SQLPostInstallerError (ODBC_ERROR_INVALID_NAME, NULL);
      goto done;
    }

  /* Retrieve the config mode */
  SQLGetConfigMode (&confMode);

  /* Retrieve the DSN if one exist */
  for (curr = (LPSTR) lpszAttributes; curr && *curr;
      curr += (STRLEN (curr) + 1))
    {
      if (!strncmp (curr, "DSN=", STRLEN ("DSN=")))
	{
	  dsn = curr + STRLEN ("DSN=");
	  break;
	}
    }

  /* Retrieve the corresponding driver */
  if (strstr (lpszDriver, "OpenLink") || strstr (lpszDriver, "Openlink")
      || strstr (lpszDriver, "oplodbc"))
    {
      driver_type = 0;

      for (curr = (LPSTR) lpszAttributes, cour = prov; curr && *curr;
	  curr += (STRLEN (curr) + 1), cour += (STRLEN (cour) + 1))
	{
	  if (!strncasecmp (curr, "Host=", STRLEN ("Host="))
	      && STRLEN (curr + STRLEN ("Host=")))
	    {
	      STRCPY (cour, curr);
	      flags |= 0x1;
	      continue;
	    }
	  if (!strncasecmp (curr, "ServerType=", STRLEN ("ServerType="))
	      && STRLEN (curr + STRLEN ("ServerType=")))
	    {
	      STRCPY (cour, curr);
	      flags |= 0x2;
	      continue;
	    }
	  STRCPY (cour, curr);
	}

      if (cour && !(flags & 1))
	{
	  STRCPY (cour, "Host=localhost\0");
	  cour += (STRLEN (cour) + 1);
	}

      if (cour && !(flags & 2))
	{
	  STRCPY (cour, "ServerType=Proxy\0");
	  cour += (STRLEN (cour) + 1);
	}

      if (cour)
	*cour = 0;
    }
  else if ((strstr (lpszDriver, "Virtuoso")
	  || strstr (lpszDriver, "virtodbc")))
    driver_type = 1;

  /* For each request */
  switch (fRequest)
    {
    case ODBC_ADD_DSN:
      /* Check if the DSN with this name already exists */

      SQLSetConfigMode (confMode);
#ifdef WIN32
      if (hwndParent && dsn
	  && SQLGetPrivateProfileString ("ODBC 32 bit Data Sources", dsn, "",
	      dsnread, sizeof (dsnread), NULL)
	  && !create_confirm (hwndParent, dsn,
	      "Are you sure you want to overwrite this DSN ?"))
#else
      if (hwndParent && dsn
	  && SQLGetPrivateProfileString ("ODBC Data Sources", dsn, "",
	      dsnread, sizeof (dsnread), NULL)
	  && !create_confirm (hwndParent, dsn,
	      "Are you sure you want to overwrite this DSN ?"))
#endif
	goto done;

      /* Call the right setup function */
      connstr =
	  create_gensetup (hwndParent, dsn,
	  STRLEN (prov) ? prov : lpszAttributes, TRUE);

      /* Check output parameters */
      if (!connstr)
	{
	  SQLPostInstallerError (ODBC_ERROR_OUT_OF_MEM, NULL);
	  goto done;
	}

      if (connstr == (LPSTR) - 1L)
	goto done;

      /* Add the DSN to the ODBC Data Sources */
      SQLSetConfigMode (confMode);
      if (!SQLWriteDSNToIni (dsn = connstr + STRLEN ("DSN="), lpszDriver))
	goto done;

      /* Add each keyword and values */
      for (curr = connstr; *curr; curr += (STRLEN (curr) + 1))
	{
	  if (strncmp (curr, "DSN=", STRLEN ("DSN=")))
	    {
	      STRCPY (dsnread, curr);
	      cour = strchr (dsnread, '=');
	      if (cour)
		*cour = 0;
	      SQLSetConfigMode (confMode);
	      if (!SQLWritePrivateProfileString (dsn, dsnread, (cour
			  && STRLEN (cour + 1)) ? cour + 1 : NULL, NULL))
		goto done;
	    }
	}

      break;

    case ODBC_CONFIG_DSN:

      if (!dsn || !STRLEN (dsn))
	{
	  SQLPostInstallerError (ODBC_ERROR_INVALID_KEYWORD_VALUE, NULL);
	  goto done;
	}

      /* Call the right setup function */
      connstr = create_gensetup (hwndParent, dsn,
	  STRLEN (prov) ? prov : lpszAttributes, FALSE);

      /* Check output parameters */
      if (!connstr)
	{
	  SQLPostInstallerError (ODBC_ERROR_OUT_OF_MEM, NULL);
	  goto done;
	}

      if (connstr == (LPSTR) - 1L)
	goto done;

      /* Compare if the DSN changed */
      if (strcmp (connstr + STRLEN ("DSN="), dsn))
	{
	  /* Remove the previous DSN */
	  SQLSetConfigMode (confMode);
	  if (!SQLRemoveDSNFromIni (dsn))
	    goto done;
	  /* Add the new DSN section */
	  SQLSetConfigMode (confMode);
	  if (!SQLWriteDSNToIni (dsn = connstr + STRLEN ("DSN="), lpszDriver))
	    goto done;
	}

      /* Add each keyword and values */
      for (curr = connstr; *curr; curr += (STRLEN (curr) + 1))
	{

	  if (strncmp (curr, "DSN=", STRLEN ("DSN=")))
	    {
	      STRCPY (dsnread, curr);
	      cour = strchr (dsnread, '=');
	      if (cour)
		*cour = 0;
	      SQLSetConfigMode (confMode);
	      if (!SQLWritePrivateProfileString (dsn, dsnread, (cour
			  && STRLEN (cour + 1)) ? cour + 1 : NULL, NULL))
		goto done;
	    }
	}

      break;

    case ODBC_REMOVE_DSN:
      if (!dsn || !STRLEN (dsn))
	{
	  SQLPostInstallerError (ODBC_ERROR_INVALID_KEYWORD_VALUE, NULL);
	  goto done;
	}

      /* Just remove the DSN */
      SQLSetConfigMode (confMode);
      if (!SQLRemoveDSNFromIni (dsn))
	goto done;
      break;
    };

quit:
  retcode = TRUE;

done:
  if (connstr && connstr != (LPSTR) - 1L && connstr != lpszAttributes
      && connstr != prov)
    free (connstr);

  return retcode;
}
Пример #7
0
bool COdbcDS::GetMxDSList(const char* pDriverName, int iType, CDSList& DSList)
{
	SQLCHAR DSNName[SQL_MAX_DSN_LENGTH + 1];
	SQLCHAR Description[100];
	SQLSMALLINT nameLen, descLen;
	SQLUSMALLINT direction;
	SQLRETURN retVal = SQL_SUCCESS;
	bool bFound = FALSE;

	// Set the config mode to the desired type.
	UWORD oldMode, newMode;

	if (iType == COdbcDS::DS_TYPE_SYS)
	{
		newMode = ODBC_SYSTEM_DSN;
		direction = SQL_FETCH_FIRST_SYSTEM;
	}
	else
	{
		newMode = ODBC_USER_DSN;
		direction = SQL_FETCH_FIRST_USER;
	}

	SQLGetConfigMode(&oldMode);
	SQLSetConfigMode(newMode);

	// Get the type of data source we're interested in.
	retVal = SQLDataSources(m_henv, direction, DSNName,	sizeof(DSNName),
							&nameLen, Description, sizeof(Description),
							&descLen);
	if (retVal == SQL_ERROR)
	{
		SQLSetConfigMode(oldMode);
		throw 4;
	}

	// Loop through all of the data sources until the one we're looking for
	// is found.
	while (retVal == SQL_SUCCESS || retVal == SQL_SUCCESS_WITH_INFO)
	{
		if (strcmp(pDriverName, (const char*)Description) == 0)
		{
			DSList.append((const char*)DSNName, pDriverName);
			bFound = true;
		}
		
		retVal = SQLDataSources(m_henv, SQL_FETCH_NEXT, DSNName,
								sizeof(DSNName), &nameLen,
								Description, sizeof(Description), &descLen);

		if (retVal == SQL_ERROR)
		{
			SQLSetConfigMode(oldMode);
			throw 4;
		}

	}

	// Restore old config mode.
	SQLSetConfigMode(oldMode);
	return bFound;
}
Пример #8
0
int
odbc_read_login_info(void)
{
	static const char *PWD = "../../../PWD";
	FILE *in = NULL;
	char line[512];
	char *s1, *s2;
	const char *const *search_p;
	char path[1024];
	int len;
#ifdef _WIN32
	UWORD old_config_mode;
#endif

	setbuf(stdout, NULL);
	setbuf(stderr, NULL);

	s1 = getenv("TDSPWDFILE");
	if (s1 && s1[0])
		in = fopen(s1, "r");
	if (!in)
		in = fopen(PWD, "r");
	if (!in)
		in = fopen("PWD", "r");

	if (!in) {
		fprintf(stderr, "Can not open PWD file\n\n");
		return 1;
	}
	while (fgets(line, 512, in)) {
		s1 = strtok(line, "=");
		s2 = strtok(NULL, "\n");
		if (!s1 || !s2)
			continue;
		if (!strcmp(s1, "UID")) {
			strcpy(odbc_user, s2);
		} else if (!strcmp(s1, "SRV")) {
			strcpy(odbc_server, s2);
		} else if (!strcmp(s1, "PWD")) {
			strcpy(odbc_password, s2);
		} else if (!strcmp(s1, "DB")) {
			strcpy(odbc_database, s2);
		}
	}
	fclose(in);

	/* find our driver */
#ifndef _WIN32
	if (!getcwd(path, sizeof(path)))
#else
	if (!_getcwd(path, sizeof(path)))
#endif
		return 0;
#ifdef __VMS
	{
	    /* A hard-coded driver path has to be in unix syntax to be recognized as such. */
	    const char *unixspec = decc$translate_vms(path);
	    if ( (int)unixspec != 0 && (int)unixspec != -1 ) strcpy(path, unixspec);
	}
#endif
	len = strlen(path);
	if (len < 10 || (strcasecmp(path + len - 10, "/unittests") != 0
#ifdef _WIN32
	    && strcasecmp(path + len - 10, "\\unittests") != 0
#endif
	    ))
		return 0;
	path[len - 9] = 0;
	for (search_p = search_driver; *search_p; ++search_p) {
		if (check_lib(path, *search_p))
			break;
	}
	if (!*search_p)
		return 0;
	strcpy(odbc_driver, path);

#ifndef _WIN32
	/* craft out odbc.ini, avoid to read wrong one */
	snprintf(path, sizeof(path), "odbc.ini.%d", (int) getpid());
	in = fopen(path, "w");
	if (in) {
		fprintf(in, "[%s]\nDriver = %s\nDatabase = %s\nServername = %s\n", odbc_server, odbc_driver, odbc_database, odbc_server);
		fclose(in);
		setenv("ODBCINI", "./odbc.ini", 1);
		setenv("SYSODBCINI", "./odbc.ini", 1);
		rename(path, "odbc.ini");
		unlink(path);
	}
#else
	if (SQLGetConfigMode(&old_config_mode)) {
		SQLSetConfigMode(ODBC_USER_DSN);
		SQLWritePrivateProfileString(odbc_server, "Driver", odbc_driver, "odbc.ini");
		SQLWritePrivateProfileString(odbc_server, "Database", odbc_database, "odbc.ini");
		SQLWritePrivateProfileString(odbc_server, "Servername", odbc_server, "odbc.ini");
		SQLSetConfigMode(old_config_mode);
	}
#endif
	return 0;
}
Пример #9
0
BOOL INSTAPI
ConfigDriver (
    HWND	  hwndParent,
    WORD	  fRequest,
    LPCSTR	  lpszDriver,
    LPCSTR	  lpszArgs,
    LPSTR	  lpszMsg,
    WORD	  cbMsgMax,
    WORD	* pcbMsgOut)
{
  char *curr, *cour;
  char driverread[4096] = { 0 };
  BOOL retcode = FALSE;
  UWORD confMode = ODBC_USER_DSN;

  /* Map the request User/System */
  if (fRequest < ODBC_INSTALL_DRIVER || fRequest > ODBC_CONFIG_DRIVER_MAX)
    {
      SQLPostInstallerError (ODBC_ERROR_INVALID_REQUEST_TYPE, NULL);
      goto done;
    }

  if (!lpszDriver || !STRLEN (lpszDriver))
    {
      SQLPostInstallerError (ODBC_ERROR_INVALID_NAME, NULL);
      goto done;
    }

  /* Retrieve the config mode */
  SQLGetConfigMode (&confMode);

  /* Treat corresponding to the request */
  switch (fRequest)
    {
    case ODBC_INSTALL_DRIVER:
      /* Check if the DRIVER with this name already exists */
      SQLSetConfigMode (confMode);
#ifdef WIN32
      if (hwndParent
	  && SQLGetPrivateProfileString ("ODBC 32 bit Drivers", lpszDriver,
	      "", driverread, sizeof (driverread), "odbcinst.ini")
	  && !create_confirm (hwndParent, NULL,
	      "Are you sure you want to overwrite this driver ?"))
#else
#  ifdef _MACX
      if (hwndParent
	  && SQLGetPrivateProfileString ("ODBC Drivers", lpszDriver, "",
	      driverread, sizeof (driverread), "odbcinst.ini")
	  && !create_confirm (hwndParent, NULL,
	      "Are you sure you want to overwrite this driver ?"))
#  else
      if (hwndParent
	  && SQLGetPrivateProfileString ("ODBC Drivers", lpszDriver, "",
	      driverread, sizeof (driverread), "odbcinst.ini")
	  && !create_confirm (hwndParent, NULL,
	      "Are you sure you want to overwrite this driver ?"))
#  endif
#endif
	{
	  SQLPostInstallerError (ODBC_ERROR_DRIVER_SPECIFIC,
	      "Driver already installed previously.");
	  goto done;
	}

      /* Add the Driver to the ODBC Drivers */
      SQLSetConfigMode (confMode);
      if (!SQLInstallDriverEx (lpszArgs, NULL, driverread,
	      sizeof (driverread), NULL, ODBC_INSTALL_COMPLETE, NULL))
	{
	  SQLPostInstallerError (ODBC_ERROR_DRIVER_SPECIFIC,
	      "Could not add the driver information.");
	  goto done;
	}

      break;

    case ODBC_CONFIG_DRIVER:
      if (!lpszArgs || !STRLEN (lpszArgs))
	{
	  SQLPostInstallerError (ODBC_ERROR_DRIVER_SPECIFIC,
	      "No enough parameters for configururation.");
	  goto done;
	}

      /* Add each keyword and values */
      for (curr = (LPSTR) lpszArgs; *curr; curr += (STRLEN (curr) + 1))
	{
	  STRCPY (driverread, curr);
	  cour = strchr (driverread, '=');
	  if (cour)
	    *cour = 0;
	  SQLSetConfigMode (confMode);
	  if (!SQLWritePrivateProfileString (lpszDriver, driverread, (cour
		      && STRLEN (cour + 1)) ? cour + 1 : NULL,
		  "odbcinst.ini"))
	    goto done;
	}
      break;

    case ODBC_REMOVE_DRIVER:
      /* Remove the Driver to the ODBC Drivers */
      SQLSetConfigMode (confMode);
      if (!SQLRemoveDriver (lpszDriver, TRUE, NULL))
	{
	  SQLPostInstallerError (ODBC_ERROR_DRIVER_SPECIFIC,
	      "Could not remove driver information.");
	  goto done;
	}
      break;

    default:
      SQLPostInstallerError (ODBC_ERROR_REQUEST_FAILED, NULL);
      goto done;
    };

quit:
  retcode = TRUE;

done:
  if (pcbMsgOut)
    *pcbMsgOut = 0;
  return retcode;
}