Exemplo n.º 1
0
int
_iodbcdm_list_entries (PCONFIG pCfg, LPCSTR lpszSection, LPSTR lpszRetBuffer, int cbRetBuffer)
{
  int curr = 0, sect_len = 0;
  lpszRetBuffer[0] = 0;

  if (!_iodbcdm_cfg_find (pCfg, (char*)lpszSection, NULL))
    {
      while (curr < cbRetBuffer && 0 == _iodbcdm_cfg_nextentry (pCfg))
	{
	  if (_iodbcdm_cfg_section (pCfg))
	    break;
	  if (_iodbcdm_cfg_define (pCfg) && pCfg->id)
	    {
	      sect_len = strlen (pCfg->id) + 1;
	      sect_len =
		  sect_len >
		  cbRetBuffer - curr ? cbRetBuffer - curr : sect_len;

	      memmove (lpszRetBuffer + curr, pCfg->id, sect_len);

	      curr += sect_len;
	    }
	}
      if (curr < cbRetBuffer)
	lpszRetBuffer[curr] = 0;
      return curr;
    }
  return 0;
}
Exemplo n.º 2
0
Arquivo: inifile.c Projeto: aosm/iodbc
BOOL
do_create_dsns (PCONFIG pCfg, PCONFIG pInfCfg, LPSTR szDriver, LPSTR szDSNS, LPSTR szDiz)
{
  char *szValue = strdup (szDSNS), *szCurr = szValue, *szComma;
  int hasMore = FALSE;
  BOOL retcode = FALSE;

  do
    {
      szComma = strchr (szCurr, ',');
      if (szComma)
	{
	  *szComma = 0;
	  hasMore = TRUE;
	}
      else
	hasMore = FALSE;

#ifdef WIN32
      if (_iodbcdm_cfg_write (pCfg, "ODBC 32 bit Data Sources", szCurr,
	      szDiz))
#else
      if (_iodbcdm_cfg_write (pCfg, "ODBC Data Sources", szCurr, szDiz))
#endif
	goto error;

      if (!ValidDSN (szCurr) || _iodbcdm_cfg_write (pCfg, szCurr, NULL, NULL))
	goto error;

      if (_iodbcdm_cfg_find (pInfCfg, szCurr, NULL)
	  && !_iodbcdm_cfg_write (pCfg, szCurr, NULL, NULL))
	{
	  if (_iodbcdm_cfg_write (pCfg, szCurr, "Driver", szDriver))
	    goto error;
	  while (!_iodbcdm_cfg_nextentry (pInfCfg)
	      && _iodbcdm_cfg_define (pInfCfg))
	    {
	      if (_iodbcdm_cfg_write (pCfg, szCurr, pInfCfg->id,
		      pInfCfg->value))
		goto error;
	    }
	}

      szCurr = szComma + 1;
    }
  while (hasMore);

  retcode = TRUE;

error:
  free (szValue);
  return retcode;
}
Exemplo n.º 3
0
Arquivo: inifile.c Projeto: aosm/iodbc
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;
}
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;
}
Exemplo n.º 5
0
BOOL
GetAvailableDrivers (LPCSTR lpszInfFile, LPSTR lpszBuf, WORD cbBufMax,
    WORD * pcbBufOut, BOOL infFile)
{
  int sect_len = 0;
  WORD curr = 0;
  BOOL retcode = FALSE;
  PCONFIG pCfg;
  char *szId;

  if (!lpszBuf || !cbBufMax)
    {
      PUSH_ERROR (ODBC_ERROR_INVALID_BUFF_LEN);
      goto quit;
    }

  /* Open the file to read from */
  if (_iodbcdm_cfg_init (&pCfg, lpszInfFile, FALSE))
    {
      PUSH_ERROR (ODBC_ERROR_COMPONENT_NOT_FOUND);
      goto quit;
    }

  /* Get the ODBC Drivers section */
#ifdef WIN32
  if (_iodbcdm_cfg_find (pCfg, "ODBC 32 bit Drivers", NULL))
#else
  if (_iodbcdm_cfg_find (pCfg, "ODBC Drivers", NULL))
#endif
    {
      PUSH_ERROR (ODBC_ERROR_COMPONENT_NOT_FOUND);
      goto done;
    }

  while (curr < cbBufMax && 0 == _iodbcdm_cfg_nextentry (pCfg))
    {
      if (_iodbcdm_cfg_section (pCfg))
	break;

      if (_iodbcdm_cfg_define (pCfg) && pCfg->id)
	{
	  szId = pCfg->id;
	  while (infFile && *szId == '"')
	    szId++;

	  sect_len = STRLEN (szId);
	  if (!sect_len)
	    {
	      PUSH_ERROR (ODBC_ERROR_INVALID_INF);
	      goto done;
	    }

	  while (infFile && *(szId + sect_len - 1) == '"')
	    sect_len -= 1;

	  sect_len = sect_len > cbBufMax - curr ? cbBufMax - curr : sect_len;

	  if (sect_len)
	    memmove (lpszBuf + curr, szId, sect_len);
	  else
	    {
	      PUSH_ERROR (ODBC_ERROR_INVALID_INF);
	      goto done;
	    }

	  curr += sect_len;
	  lpszBuf[curr++] = 0;
	}
    }

  if (curr < cbBufMax)
    lpszBuf[curr + 1] = 0;
  if (pcbBufOut)
    *pcbBufOut = curr;
  retcode = TRUE;

done:
  _iodbcdm_cfg_done (pCfg);

quit:
  return retcode;
}
Exemplo n.º 6
0
BOOL INSTAPI
GetTranslator (HWND hwndParent, LPSTR lpszName, WORD cbNameMax,
    WORD * pcbNameOut, LPSTR lpszPath, WORD cbPathMax,
    WORD * pcbPathOut, DWORD * pvOption)
{
  pConfigTranslatorFunc pConfigTranslator;
  pTrsChooseFunc pTrsChoose;
  BOOL retcode = FALSE, finish = FALSE;
  PCONFIG pCfg;
  UWORD configMode;
  RETCODE ret = SQL_NO_DATA;
  void *handle;
  char translator[1024];
#if defined (__APPLE__) && !defined (NO_FRAMEWORKS)
  CFBundleRef bundle = NULL;
  CFBundleRef bundle_dll = NULL;
  CFURLRef liburl;
#endif

  do
    {
      /* Load the Admin dialbox function */
#if defined (__APPLE__)
# if !defined(NO_FRAMEWORKS)
      bundle = CFBundleGetBundleWithIdentifier (CFSTR ("org.iodbc.core"));
      if (bundle)
	{
	  /* Search for the iODBCadm library */
	  liburl =
	      CFBundleCopyResourceURL (bundle, CFSTR ("iODBCadm.bundle"),
	      NULL, NULL);
	  if (liburl)
	    {
      	      bundle_dll = CFBundleCreate (NULL, liburl);
              CFRelease (liburl);
      	      CALL_TRSCHOOSE_DIALBOX_BUNDLE ();
	    }
	}
# endif
#else

      CALL_TRSCHOOSE_DIALBOX ("libiodbcadm.so.2");
#endif

      if (ret == SQL_NO_DATA)
	{
	  if (pcbNameOut)
	    *pcbNameOut = 0;
	  if (pcbPathOut)
	    *pcbPathOut = 0;
	  finish = TRUE;
	}

      if (ret == SQL_SUCCESS)
	{
	  STRNCPY (lpszName, translator + STRLEN ("TranslationName="),
	      cbNameMax - 1);
	  if (pcbNameOut)
	    *pcbNameOut = STRLEN (lpszName);

	  /* Get it from the user odbcinst file */
	  wSystemDSN = USERDSN_ONLY;
	  if (!_iodbcdm_cfg_search_init (&pCfg, "odbcinst.ini", TRUE))
	    {
	      if (!_iodbcdm_cfg_find (pCfg, (char *) lpszName, "Setup"))
		CALL_CONFIG_TRANSLATOR (pCfg->value);
	      if (!_iodbcdm_cfg_find (pCfg, (char *) lpszName, "Translator"))
		CALL_CONFIG_TRANSLATOR (pCfg->value);
	      if (!access (lpszName, X_OK))
		CALL_CONFIG_TRANSLATOR (lpszName);
	      if (!_iodbcdm_cfg_find (pCfg, "Default", "Setup"))
		CALL_CONFIG_TRANSLATOR (pCfg->value);
	      if (!_iodbcdm_cfg_find (pCfg, "Default", "Translator"))
		CALL_CONFIG_TRANSLATOR (pCfg->value);
	    }

	  /* Get it from the system odbcinst file */
	  if (pCfg)
	    {
	      _iodbcdm_cfg_done (pCfg);
	      pCfg = NULL;
	    }
	  wSystemDSN = SYSTEMDSN_ONLY;
	  if (!_iodbcdm_cfg_search_init (&pCfg, "odbcinst.ini", TRUE))
	    {
	      if (!_iodbcdm_cfg_find (pCfg, (char *) lpszName, "Setup"))
		CALL_CONFIG_TRANSLATOR (pCfg->value);
	      if (!_iodbcdm_cfg_find (pCfg, (char *) lpszName, "Translator"))
		CALL_CONFIG_TRANSLATOR (pCfg->value);
	      if (!access (lpszName, X_OK))
		CALL_CONFIG_TRANSLATOR (lpszName);
	      if (!_iodbcdm_cfg_find (pCfg, "Default", "Setup"))
		CALL_CONFIG_TRANSLATOR (pCfg->value);
	      if (!_iodbcdm_cfg_find (pCfg, "Default", "Translator"))
		CALL_CONFIG_TRANSLATOR (pCfg->value);
	    }

	  /* The last ressort, a proxy driver */
	  CALL_CONFIG_TRANSLATOR ("libtranslator.so.2");

	  /* Error : ConfigDSN could no be found */
	  PUSH_ERROR (ODBC_ERROR_LOAD_LIB_FAILED);

	done:
	  STRNCPY (lpszPath, pCfg->fileName, cbPathMax - 1);
	  if (pcbPathOut)
	    *pcbPathOut = STRLEN (lpszPath);
	  _iodbcdm_cfg_done (pCfg);
	}
    }
  while (!finish);

  retcode = TRUE;

  wSystemDSN = USERDSN_ONLY;
  configMode = ODBC_BOTH_DSN;

  return retcode;
}
Exemplo n.º 7
0
BOOL INSTAPI
SQLConfigDriver_Internal (HWND hwndParent, WORD fRequest, LPCSTR lpszDriver,
    LPCSTR lpszArgs, LPSTR lpszMsg, WORD cbMsgMax, WORD FAR * pcbMsgOut,
    SQLCHAR waMode)
{
  PCONFIG pCfg;
  BOOL retcode = FALSE;
  void *handle;
  pConfigDriverFunc pConfigDriver;
  pConfigDriverWFunc pConfigDriverW;
#if defined (__APPLE__) && !(defined (NO_FRAMEWORKS) || defined (_LP64))
  CFStringRef libname = NULL;
  CFBundleRef bundle;
  CFURLRef liburl;
  char name[1024] = { 0 };
#endif
  char *_drv_u8 = NULL;

  /* Check input parameters */
  CLEAR_ERROR ();

  if (waMode == 'W')
    {
      _drv_u8 = (char *) dm_SQL_WtoU8 ((SQLWCHAR *) lpszDriver, SQL_NTS);
      if (_drv_u8 == NULL && lpszDriver)
	{
	  PUSH_ERROR (ODBC_ERROR_OUT_OF_MEM);
	  goto quit;
	}
    }
  else
    _drv_u8 = (char *) lpszDriver;

  if (!_drv_u8 || !STRLEN (_drv_u8))
    {
      PUSH_ERROR (ODBC_ERROR_INVALID_NAME);
      goto quit;
    }

  /* Map the request User/System */
  if (fRequest < ODBC_INSTALL_DRIVER || fRequest > ODBC_CONFIG_DRIVER_MAX)
    {
      PUSH_ERROR (ODBC_ERROR_INVALID_REQUEST_TYPE);
      goto quit;
    }

  /* Get it from the user odbcinst file */
  wSystemDSN = USERDSN_ONLY;
  if (!_iodbcdm_cfg_search_init (&pCfg, "odbcinst.ini", TRUE))
    {
      if (!_iodbcdm_cfg_find (pCfg, (char *) _drv_u8, "Setup"))
	{
	  if (waMode == 'A')
	    {
	      CALL_CONFIG_DRIVER (pCfg->value);
	    }
	  else
	    {
	      CALL_CONFIG_DRIVERW (pCfg->value);
	    }
	}
      if (!_iodbcdm_cfg_find (pCfg, (char *) _drv_u8, "Driver"))
	{
	  if (waMode == 'A')
	    {
	      CALL_CONFIG_DRIVER (pCfg->value);
	    }
	  else
	    {
	      CALL_CONFIG_DRIVERW (pCfg->value);
	    }
	}
      if (!access (_drv_u8, X_OK))
	{
	  if (waMode == 'A')
	    {
	      CALL_CONFIG_DRIVER (_drv_u8);
	    }
	  else
	    {
	      CALL_CONFIG_DRIVERW (_drv_u8);
	    }
	}
      if (!_iodbcdm_cfg_find (pCfg, "Default", "Setup"))
	{
	  if (waMode == 'A')
	    {
	      CALL_CONFIG_DRIVER (pCfg->value);
	    }
	  else
	    {
	      CALL_CONFIG_DRIVERW (pCfg->value);
	    }
	}
      if (!_iodbcdm_cfg_find (pCfg, "Default", "Driver"))
	{
	  if (waMode == 'A')
	    {
	      CALL_CONFIG_DRIVER (pCfg->value);
	    }
	  else
	    {
	      CALL_CONFIG_DRIVERW (pCfg->value);
	    }
	}
    }

  /* Get it from the system odbcinst file */
  if (pCfg)
    {
      _iodbcdm_cfg_done (pCfg);
      pCfg = NULL;
    }
  wSystemDSN = SYSTEMDSN_ONLY;
  if (!_iodbcdm_cfg_search_init (&pCfg, "odbcinst.ini", TRUE))
    {
      if (!_iodbcdm_cfg_find (pCfg, (char *) _drv_u8, "Setup"))
	{
	  if (waMode == 'A')
	    {
	      CALL_CONFIG_DRIVER (pCfg->value);
	    }
	  else
	    {
	      CALL_CONFIG_DRIVERW (pCfg->value);
	    }
	}
      if (!_iodbcdm_cfg_find (pCfg, (char *) _drv_u8, "Driver"))
	{
	  if (waMode == 'A')
	    {
	      CALL_CONFIG_DRIVER (pCfg->value);
	    }
	  else
	    {
	      CALL_CONFIG_DRIVERW (pCfg->value);
	    }
	}
      if (!access (_drv_u8, X_OK))
	{
	  if (waMode == 'A')
	    {
	      CALL_CONFIG_DRIVER (_drv_u8);
	    }
	  else
	    {
	      CALL_CONFIG_DRIVERW (_drv_u8);
	    }
	}
      if (!_iodbcdm_cfg_find (pCfg, "Default", "Setup"))
	{
	  if (waMode == 'A')
	    {
	      CALL_CONFIG_DRIVER (pCfg->value);
	    }
	  else
	    {
	      CALL_CONFIG_DRIVERW (pCfg->value);
	    }
	}
      if (!_iodbcdm_cfg_find (pCfg, "Default", "Driver"))
	{
	  if (waMode == 'A')
	    {
	      CALL_CONFIG_DRIVER (pCfg->value);
	    }
	  else
	    {
	      CALL_CONFIG_DRIVERW (pCfg->value);
	    }
	}
    }

  /* The last ressort, a proxy driver */
#if defined (__APPLE__) && !(defined (NO_FRAMEWORKS) || defined (_LP64))
  bundle = CFBundleGetBundleWithIdentifier (CFSTR ("org.iodbc.inst"));
  if (bundle)
    {
      /* Search for the drvproxy library */
      liburl =
	  CFBundleCopyResourceURL (bundle, CFSTR ("iODBCdrvproxy.bundle"),
	  NULL, NULL);
      if (liburl
	  && (libname =
	      CFURLCopyFileSystemPath (liburl, kCFURLPOSIXPathStyle)))
	{
	  CFStringGetCString (libname, name, sizeof (name),
	      kCFStringEncodingASCII);
	  strcat (name, "/Contents/MacOS/iODBCdrvproxy");
	  if (waMode == 'A')
	    {
	      CALL_CONFIG_DRIVER (name);
	    }
	  else
	    {
	      CALL_CONFIG_DRIVERW (name);
	    }
	}
      if (liburl)
	CFRelease (liburl);
      if (libname)
	CFRelease (libname);
    }
#else
  if (waMode == 'A')
    {
      CALL_CONFIG_DRIVER ("libdrvproxy.so.2");
    }
  else
    {
      CALL_CONFIG_DRIVERW ("libdrvproxy.so.2");
    }
#endif

  /* Error : ConfigDriver could no be found */
  PUSH_ERROR (ODBC_ERROR_LOAD_LIB_FAILED);

done:
  if (pCfg)
    _iodbcdm_cfg_done (pCfg);

quit:
  if (_drv_u8 != lpszDriver)
    MEM_FREE (_drv_u8);

  wSystemDSN = USERDSN_ONLY;
  configMode = ODBC_BOTH_DSN;

  if (pcbMsgOut)
    *pcbMsgOut = 0;

  return retcode;
}
Exemplo n.º 8
0
static int
_fix_home_odbc(PCONFIG pconf, char *lib_odbcini, int bIsInst)
{
  char pathbuf[1024];
  char *home_odbcini = _getinifilename (pathbuf, sizeof (pathbuf), bIsInst, TRUE);

  if (home_odbcini && lib_odbcini)
    {
      PCONFIG pCfg = NULL;
      stat_t home_stat;
      stat_t lib_stat;

      if (access(home_odbcini, R_OK)!=0)
        {
          symlink(lib_odbcini, home_odbcini);
          return 0;
        }
        else
        {
          char buf[4096];
          int rc;

          if (stat(home_odbcini, &home_stat))
            return -1;

          /* 
           * if $HOME/.odbc[inst].ini is link 
           *  to $HOME/Library/ODBC/odbc[inst].ini 
           */
          if ((home_stat.st_mode & S_IFLNK) 
              && (rc = readlink(home_odbcini, buf, sizeof(buf)))>0)
            {
              buf[rc]=0; 
              if (strcmp(buf,lib_odbcini)==0)
                return 0; /* OK  $HOME/.odbc.ini is linked to odbc.ini */
            }

          if (stat(lib_odbcini, &lib_stat))
            return -1;

          /* if $HOME/Library/ODBC/odbc[inst].ini is link 
           *  to $HOME/.odbc[inst].ini 
           */
          if ((lib_stat.st_mode & S_IFLNK) 
              && (rc = readlink(lib_odbcini, buf, sizeof(buf)))>0)
            { 
              buf[rc]=0; 
              if (strcmp(buf,home_odbcini)==0)
                return 0; /* OK  $HOME/.odbc.ini is linked to odbc.ini */
            }
        }

      /* 
       * import $HOME/.odbc[inst].ini and replace it with link 
       *  to $HOME/Library/ODBC/odbc[inst].ini 
       */
      if (!_iodbcdm_cfg_init (&pCfg, home_odbcini, FALSE))
        {
          int len = 0;
          char root_buf[4096] = {0};
          char *proot;
          char *root_val = NULL;
          int was_error = FALSE;
          char *root_lst = bIsInst?DRV_LST:DSN_LST;

          /* Move DSN/Driver list*/
          len = _iodbcdm_list_entries (pCfg, root_lst, root_buf, sizeof(root_buf));
          if (len >0)
            {
              /* move [ODBC Data Sources] section */
              for(proot = root_buf; *proot; proot += STRLEN(proot) + 1)
                {
                  if (!_iodbcdm_cfg_find (pCfg, root_lst, proot))
                    root_val = pCfg->value;
                  else
                    root_val = NULL;

                  if (!proot || !root_val) 
                    continue;

                  if (_iodbcdm_cfg_write (pconf, root_lst, proot, root_val)
                      || _iodbcdm_cfg_commit (pconf))
      		    {
      		      was_error = TRUE;
                      break;
                    }
                }

              /* move DSN defines */
              for(proot = root_buf; *proot; proot += STRLEN(proot) + 1)
                {
                  char buffer[4096];
                  char *pattr;
                  char *pattr_val;

                  len = _iodbcdm_list_entries (pCfg, proot, buffer, sizeof(buffer));
                  if (len>0)
                    {
                      /* move [DSN] description */
                      for(pattr = buffer; *pattr; pattr += STRLEN(pattr) + 1)
                        {
                          if (!_iodbcdm_cfg_find (pCfg, proot, pattr))
                            pattr_val = pCfg->value;
                          else
                            pattr_val = NULL;
                      

                          if (!pattr || !pattr_val)
                            continue;
                          
                          if (_iodbcdm_cfg_write (pconf, proot, pattr, pattr_val)
                              || _iodbcdm_cfg_commit (pconf))
      			    {
      			      was_error = TRUE;
                              break;
                            }
                        }
                    }
                }
            }
          if (was_error)
            return -1;
        }
     /* make link */
      if (access(home_odbcini, R_OK)==0)
        {
          if (unlink(home_odbcini))
            return -1;
        }

      if (symlink(lib_odbcini, home_odbcini))
        return -1;
    }
  return 0;
}