ConfigDriver.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * ConfigDriver.c
  3. *
  4. * $Id$
  5. *
  6. * The iODBC driver manager.
  7. *
  8. * Copyright (C) 1996-2021 OpenLink Software <[email protected]>
  9. * All Rights Reserved.
  10. *
  11. * This software is released under the terms of either of the following
  12. * licenses:
  13. *
  14. * - GNU Library General Public License (see LICENSE.LGPL)
  15. * - The BSD License (see LICENSE.BSD).
  16. *
  17. * Note that the only valid version of the LGPL license as far as this
  18. * project is concerned is the original GNU Library General Public License
  19. * Version 2, dated June 1991.
  20. *
  21. * While not mandated by the BSD license, any patches you make to the
  22. * iODBC source code may be contributed back into the iODBC project
  23. * at your discretion. Contributions will benefit the Open Source and
  24. * Data Access community as a whole. Submissions may be made at:
  25. *
  26. * http://www.iodbc.org
  27. *
  28. *
  29. * GNU Library Generic Public License Version 2
  30. * ============================================
  31. * This library is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU Library General Public
  33. * License as published by the Free Software Foundation; only
  34. * Version 2 of the License dated June 1991.
  35. *
  36. * This library is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  39. * Library General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU Library General Public
  42. * License along with this library; if not, write to the Free
  43. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  44. *
  45. *
  46. * The BSD License
  47. * ===============
  48. * Redistribution and use in source and binary forms, with or without
  49. * modification, are permitted provided that the following conditions
  50. * are met:
  51. *
  52. * 1. Redistributions of source code must retain the above copyright
  53. * notice, this list of conditions and the following disclaimer.
  54. * 2. Redistributions in binary form must reproduce the above copyright
  55. * notice, this list of conditions and the following disclaimer in
  56. * the documentation and/or other materials provided with the
  57. * distribution.
  58. * 3. Neither the name of OpenLink Software Inc. nor the names of its
  59. * contributors may be used to endorse or promote products derived
  60. * from this software without specific prior written permission.
  61. *
  62. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  63. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  64. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  65. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR
  66. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  67. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  68. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  69. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  70. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  71. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  72. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  73. */
  74. #include <iodbc.h>
  75. #include <odbcinst.h>
  76. #include <iodbc_error.h>
  77. #include <iodbcadm.h>
  78. #include "gui.h"
  79. BOOL INSTAPI
  80. ConfigDriver (
  81. HWND hwndParent,
  82. WORD fRequest,
  83. LPCSTR lpszDriver,
  84. LPCSTR lpszArgs,
  85. LPSTR lpszMsg,
  86. WORD cbMsgMax,
  87. WORD * pcbMsgOut)
  88. {
  89. char *curr, *cour;
  90. char driverread[4096] = { 0 };
  91. BOOL retcode = FALSE;
  92. UWORD confMode = ODBC_USER_DSN;
  93. /* Map the request User/System */
  94. if (fRequest < ODBC_INSTALL_DRIVER || fRequest > ODBC_CONFIG_DRIVER_MAX)
  95. {
  96. SQLPostInstallerError (ODBC_ERROR_INVALID_REQUEST_TYPE, NULL);
  97. goto done;
  98. }
  99. if (!lpszDriver || !STRLEN (lpszDriver))
  100. {
  101. SQLPostInstallerError (ODBC_ERROR_INVALID_NAME, NULL);
  102. goto done;
  103. }
  104. /* Retrieve the config mode */
  105. SQLGetConfigMode (&confMode);
  106. /* Treat corresponding to the request */
  107. switch (fRequest)
  108. {
  109. case ODBC_INSTALL_DRIVER:
  110. /* Check if the DRIVER with this name already exists */
  111. SQLSetConfigMode (confMode);
  112. #ifdef WIN32
  113. if (hwndParent
  114. && SQLGetPrivateProfileString ("ODBC 32 bit Drivers", lpszDriver,
  115. "", driverread, sizeof (driverread), "odbcinst.ini")
  116. && !create_confirm (hwndParent, NULL,
  117. "Are you sure you want to overwrite this driver ?"))
  118. #else
  119. # ifdef _MACX
  120. if (hwndParent
  121. && SQLGetPrivateProfileString ("ODBC Drivers", lpszDriver, "",
  122. driverread, sizeof (driverread), "odbcinst.ini")
  123. && !create_confirm (hwndParent, NULL,
  124. "Are you sure you want to overwrite this driver ?"))
  125. # else
  126. if (hwndParent
  127. && SQLGetPrivateProfileString ("ODBC Drivers", lpszDriver, "",
  128. driverread, sizeof (driverread), "odbcinst.ini")
  129. && !create_confirm (hwndParent, NULL,
  130. "Are you sure you want to overwrite this driver ?"))
  131. # endif
  132. #endif
  133. {
  134. SQLPostInstallerError (ODBC_ERROR_DRIVER_SPECIFIC,
  135. "Driver already installed previously.");
  136. goto done;
  137. }
  138. /* Add the Driver to the ODBC Drivers */
  139. SQLSetConfigMode (confMode);
  140. if (!SQLInstallDriverEx (lpszArgs, NULL, driverread,
  141. sizeof (driverread), NULL, ODBC_INSTALL_COMPLETE, NULL))
  142. {
  143. SQLPostInstallerError (ODBC_ERROR_DRIVER_SPECIFIC,
  144. "Could not add the driver information.");
  145. goto done;
  146. }
  147. break;
  148. case ODBC_CONFIG_DRIVER:
  149. if (!lpszArgs || !STRLEN (lpszArgs))
  150. {
  151. SQLPostInstallerError (ODBC_ERROR_DRIVER_SPECIFIC,
  152. "No enough parameters for configururation.");
  153. goto done;
  154. }
  155. /* Add each keyword and values */
  156. for (curr = (LPSTR) lpszArgs; *curr; curr += (STRLEN (curr) + 1))
  157. {
  158. STRCPY (driverread, curr);
  159. cour = strchr (driverread, '=');
  160. if (cour)
  161. *cour = 0;
  162. SQLSetConfigMode (confMode);
  163. if (!SQLWritePrivateProfileString (lpszDriver, driverread, (cour
  164. && STRLEN (cour + 1)) ? cour + 1 : NULL,
  165. "odbcinst.ini"))
  166. goto done;
  167. }
  168. break;
  169. case ODBC_REMOVE_DRIVER:
  170. /* Remove the Driver to the ODBC Drivers */
  171. SQLSetConfigMode (confMode);
  172. if (!SQLRemoveDriver (lpszDriver, TRUE, NULL))
  173. {
  174. SQLPostInstallerError (ODBC_ERROR_DRIVER_SPECIFIC,
  175. "Could not remove driver information.");
  176. goto done;
  177. }
  178. break;
  179. default:
  180. SQLPostInstallerError (ODBC_ERROR_REQUEST_FAILED, NULL);
  181. goto done;
  182. };
  183. quit:
  184. retcode = TRUE;
  185. done:
  186. if (pcbMsgOut)
  187. *pcbMsgOut = 0;
  188. return retcode;
  189. }