Beispiel #1
0
BOOL
install_from_ini (PCONFIG pCfg, PCONFIG pOdbcCfg, LPSTR szInfFile, LPSTR szDriver, BOOL drivers)
{
  PCONFIG pInfCfg;
  char *szKeysSection = NULL, *szDriverFile = NULL, *szSetupFile = NULL,
      *szValue = NULL, *szId = NULL, *szComma, *szComma1;
  BOOL ret = FALSE;

  if (_iodbcdm_cfg_write (pCfg, szDriver, NULL, NULL))
    return ret;

  if (_iodbcdm_cfg_init (&pInfCfg, szInfFile, FALSE))
    return ret;

  if (_iodbcdm_cfg_find (pInfCfg,
	  drivers ? "ODBC Drivers" : "ODBC Translators", szDriver))
    goto error;

#ifdef WIN32
  if (_iodbcdm_cfg_write (pCfg,
	  drivers ? "ODBC 32 bit Drivers" : "ODBC 32 bit Translators",
	  szDriver, "Installed"))
#else
  if (_iodbcdm_cfg_write (pCfg, drivers ? "ODBC Drivers" : "ODBC Translators",
	  szDriver, "Installed"))
#endif
    goto error;

  if (_iodbcdm_cfg_find (pInfCfg, szDriver,
	  drivers ? "Driver" : "Translator"))
    goto error;

  szComma = strchr (pInfCfg->value, ',');
  szComma1 = strchr (szComma + 1, ',');
  if (!szComma || !szComma1 || szComma + 1 == szComma1)
    goto error;

  *szComma1 = 0;
  szDriverFile = strdup (szComma + 1);
  if (_iodbcdm_cfg_write (pCfg, szDriver, drivers ? "Driver" : "Translator",
	  szDriverFile))
    goto error;

  if (!_iodbcdm_cfg_find (pInfCfg, szDriver, "Setup"))
    {
      szComma = strchr (pInfCfg->value, ',');
      szComma1 = strchr (szComma + 1, ',');
      if (!szComma || !szComma1 || szComma + 1 == szComma1)
	goto error;

      *szComma1 = 0;
      szSetupFile = strdup (szComma + 1);

      if (_iodbcdm_cfg_write (pCfg, szDriver, "Setup", szSetupFile))
	goto error;
    }

  if (!_iodbcdm_cfg_find (pInfCfg, szDriver, NULL))
    {
      while (!_iodbcdm_cfg_nextentry (pInfCfg)
	  && _iodbcdm_cfg_define (pInfCfg))
	if (strcmp (pInfCfg->id, drivers ? "\"Driver\"" : "\"Translator\"")
	    && strcmp (pInfCfg->id, "\"Setup\""))
	  {
	    szComma = strchr (pInfCfg->value, ',');
	    szComma1 = strchr (szComma + 1, ',');
	    if (!szComma || !szComma1 || szComma + 1 == szComma1)
	      szValue = strdup ("");
	    else
	      {
		*szComma1 = 0;
		szValue = strdup (szComma + 1);
	      }

	    szComma = strchr (pInfCfg->id, '"');
	    szComma1 = strchr (szComma + 1, '"');
	    if (!szComma || !szComma1 || szComma + 1 == szComma1)
	      goto loop_cont;
	    else
	      {
		*szComma1 = 0;
		szId = strdup (szComma + 1);
	      }

	    if (_iodbcdm_cfg_write (pCfg, szDriver, szId, szValue))
	      goto error;

	  loop_cont:
	    if (szValue)
	      {
		free (szValue);
		szValue = NULL;
	      }
	    if (szId)
	      {
		free (szId);
		szId = NULL;
	      }
	  }
    }

  if (!drivers)
    goto quit;

  szKeysSection = (char *) calloc (strlen (szDriver) + 6, sizeof (char));
  strcpy (szKeysSection, szDriver);
  strcat (szKeysSection, "-Keys");

  if (!_iodbcdm_cfg_find (pInfCfg, szKeysSection, NULL))
    {
      while (!_iodbcdm_cfg_nextentry (pInfCfg)
	  && _iodbcdm_cfg_define (pInfCfg))
	{
	  if (strcmp (pInfCfg->id, "CreateDSN"))
	    {
	      if (_iodbcdm_cfg_write (pCfg, szDriver, pInfCfg->id,
		      pInfCfg->value))
		goto error;
	    }
	  else if (!do_create_dsns (pOdbcCfg, pCfg, szDriverFile,
		  pInfCfg->value, szDriver))
	    goto error;
	}
    }

quit:
  ret = TRUE;

error:
  if (szKeysSection)
    free (szKeysSection);
  if (szDriverFile)
    free (szDriverFile);
  if (szSetupFile)
    free (szSetupFile);
  if (szValue)
    free (szValue);
  if (szId)
    free (szId);
  _iodbcdm_cfg_done (pInfCfg);
  return ret;
}
Beispiel #2
0
BOOL INSTAPI
SQLRemoveDriver (LPCSTR lpszDriver, BOOL fRemoveDSN, LPDWORD lpdwUsageCount)
{
  /*char *szDriverFile = NULL; */
  BOOL retcode = FALSE;
  PCONFIG pCfg = NULL, pInstCfg = NULL;
  LPSTR entries = (LPSTR) malloc (sizeof (char) * 65535), curr;
  int len = 0, i = 0;

  /* Check input parameters */
  CLEAR_ERROR ();
  if (!lpszDriver || !STRLEN (lpszDriver))
    {
      PUSH_ERROR (ODBC_ERROR_INVALID_NAME);
      goto quit;
    }

  /* Else go through user/system odbcinst.ini */
  switch (configMode)
    {
    case ODBC_BOTH_DSN:
    case ODBC_USER_DSN:
      wSystemDSN = USERDSN_ONLY;
      break;

    case ODBC_SYSTEM_DSN:
      wSystemDSN = SYSTEMDSN_ONLY;
      break;
    }

  if (_iodbcdm_cfg_search_init (&pCfg, "odbc.ini", FALSE))
    {
      PUSH_ERROR (ODBC_ERROR_GENERAL_ERR);
      goto done;
    }

  if (_iodbcdm_cfg_search_init (&pInstCfg, "odbcinst.ini", FALSE))
    {
      PUSH_ERROR (ODBC_ERROR_GENERAL_ERR);
      goto done;
    }

  if (fRemoveDSN)
    {
#ifdef WIN32
      if (entries &&
	  (len = _iodbcdm_list_entries (pCfg, "ODBC 32 bit Data Sources",
		  entries, 65535)))
#else
      if (entries
	  && (len =
	      _iodbcdm_list_entries (pCfg, "ODBC Data Sources", entries,
		  65535)))
#endif
	{
	  for (curr = entries; i < len;
	      i += (STRLEN (curr) + 1), curr += (STRLEN (curr) + 1))
	    {
	      int nCursor = pCfg->cursor;

	      if (_iodbcdm_cfg_rewind (pCfg))
		{
		  PUSH_ERROR (ODBC_ERROR_GENERAL_ERR);
		  goto done;
		}

#ifdef WIN32
	      if (_iodbcdm_cfg_find (pCfg, "ODBC 32 bit Data Sources", curr))
#else
	      if (_iodbcdm_cfg_find (pCfg, "ODBC Data Sources", curr))
#endif
		{
		  if (_iodbcdm_cfg_rewind (pCfg))
		    {
		      PUSH_ERROR (ODBC_ERROR_GENERAL_ERR);
		      goto done;
		    }
		  pCfg->cursor = nCursor;
		  continue;
		}

	      if (!strcmp (pCfg->value, lpszDriver))
		{
		  if (_iodbcdm_cfg_write (pCfg, curr, NULL, NULL))
		    {
		      PUSH_ERROR (ODBC_ERROR_GENERAL_ERR);
		      goto done;
		    }

#ifdef WIN32
		  if (_iodbcdm_cfg_write (pCfg, "ODBC 32 bit Data Sources",
			  curr, NULL))
#else
		  if (_iodbcdm_cfg_write (pCfg, "ODBC Data Sources", curr,
			  NULL))
#endif
		    {
		      PUSH_ERROR (ODBC_ERROR_GENERAL_ERR);
		      goto done;
		    }
		}

	      pCfg->cursor = nCursor;
	    }
	}
    }

  if (_iodbcdm_cfg_write (pInstCfg, (char *) lpszDriver, NULL, NULL))
    {
      PUSH_ERROR (ODBC_ERROR_GENERAL_ERR);
      goto done;
    }

#ifdef WIN32
  if (_iodbcdm_cfg_write (pInstCfg, "ODBC 32 bit Drivers", lpszDriver, NULL))
#else
  if (_iodbcdm_cfg_write (pInstCfg, "ODBC Drivers", (LPSTR) lpszDriver, NULL))
#endif
    {
      PUSH_ERROR (ODBC_ERROR_GENERAL_ERR);
      goto done;
    }

  if (_iodbcdm_cfg_commit (pCfg) || _iodbcdm_cfg_commit (pInstCfg))
    {
      PUSH_ERROR (ODBC_ERROR_GENERAL_ERR);
      goto done;
    }

  retcode = TRUE;

done:
  if (pCfg)
    _iodbcdm_cfg_done (pCfg);
  if (pInstCfg)
    _iodbcdm_cfg_done (pInstCfg);
  if (entries)
    free (entries);

quit:
  wSystemDSN = USERDSN_ONLY;
  configMode = ODBC_BOTH_DSN;

  return retcode;
}
Beispiel #3
0
BOOL INSTAPI
SQLInstallTranslator (LPCSTR lpszInfFile, LPCSTR lpszTranslator,
    LPCSTR lpszPathIn, LPSTR lpszPathOut, WORD cbPathOutMax,
    WORD * pcbPathOut, WORD fRequest, LPDWORD lpdwUsageCount)
{
  PCONFIG pCfg = NULL, pOdbcCfg = NULL;
  BOOL retcode = FALSE;

  /* Check input parameters */
  CLEAR_ERROR ();

  if (lpszPathIn && access (lpszPathIn, R_OK | W_OK | X_OK))
    {
      PUSH_ERROR (ODBC_ERROR_INVALID_PATH);
      goto quit;
    }

  switch (fRequest)
    {
    case ODBC_INSTALL_INQUIRY:
      if (lpszPathIn)
	{
	  if (pcbPathOut)
	    *pcbPathOut = STRLEN (lpszPathIn);
	  retcode = TRUE;
	}
      else
	retcode = InstallDriverPathLength (pcbPathOut, "ODBCTRANSLATORS");
      goto quit;

    case ODBC_INSTALL_COMPLETE:
      break;

    default:
      PUSH_ERROR (ODBC_ERROR_INVALID_REQUEST_TYPE);
      goto quit;
    }

  /* Check input parameters */
  if (!lpszTranslator || !STRLEN (lpszTranslator))
    {
      PUSH_ERROR (ODBC_ERROR_INVALID_PARAM_SEQUENCE);
      goto quit;
    }

  if (!lpszPathOut || !cbPathOutMax)
    {
      PUSH_ERROR (ODBC_ERROR_INVALID_BUFF_LEN);
      goto quit;
    }

  /* Write the out path */
  if (!InstallDriverPath (lpszPathOut, cbPathOutMax, pcbPathOut,
	  "ODBCTRANSLATORS"))
    goto quit;

  /* Else go through user/system odbcinst.ini */
  switch (configMode)
    {
    case ODBC_BOTH_DSN:
    case ODBC_USER_DSN:
      wSystemDSN = USERDSN_ONLY;
      break;

    case ODBC_SYSTEM_DSN:
      wSystemDSN = SYSTEMDSN_ONLY;
      break;
    }

  if (_iodbcdm_cfg_search_init (&pCfg, "odbcinst.ini", TRUE))
    {
      PUSH_ERROR (ODBC_ERROR_GENERAL_ERR);
      goto quit;
    }

  if (_iodbcdm_cfg_search_init (&pOdbcCfg, "odbc.ini", TRUE))
    {
      PUSH_ERROR (ODBC_ERROR_GENERAL_ERR);
      pOdbcCfg = NULL;
      goto done;
    }

  if (lpszInfFile)
    {
      if (!install_from_ini (pCfg, pOdbcCfg, (char *) lpszInfFile,
	      (char *) lpszTranslator, FALSE))
	{
	  PUSH_ERROR (ODBC_ERROR_INVALID_INF);
	  goto done;
	}
    }
  else if (!install_from_string (pCfg, pOdbcCfg, (char *) lpszTranslator,
	  FALSE))
    {
      PUSH_ERROR (ODBC_ERROR_INVALID_KEYWORD_VALUE);
      goto done;
    }

  if (_iodbcdm_cfg_commit (pCfg) || _iodbcdm_cfg_commit (pOdbcCfg))
    {
      PUSH_ERROR (ODBC_ERROR_GENERAL_ERR);
      goto done;
    }

  retcode = TRUE;

done:
  _iodbcdm_cfg_done (pCfg);
  if (pOdbcCfg)
    _iodbcdm_cfg_done (pOdbcCfg);

quit:
  wSystemDSN = USERDSN_ONLY;
  configMode = ODBC_BOTH_DSN;

  return retcode;
}