Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
7.5 KiB

  1. /*
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. PowerBuilder.cpp
  5. Abstract:
  6. This fixes a profiles bug in PowerBuilder where it adds reg keys to HKCU
  7. which point to various paths in the install location, essentially by adding
  8. User ODBC datasources, which should've been System ODBC datasources, hence
  9. installed under HKLM.
  10. This shim recreates the registry values expected in HKCU for other users:
  11. HKCU\Software\ODBC\ODBC.INI\ODBC Data Sources\Powersoft Demo DB V6 =
  12. "Sybase SQL Anywhere 5.0"
  13. HKCU\Software\ODBC\ODBC.INI\Powersoft Demo DB V6\DataBaseFile =
  14. "<install1>\demodb\psDemoDB.db"
  15. HKCU\Software\ODBC\ODBC.INI\Powersoft Demo DB V6\DataBaseName = "psDemoDB"
  16. HKCU\Software\ODBC\ODBC.INI\Powersoft Demo DB V6\Driver =
  17. "<install2>\WOD50T.DLL"
  18. HKCU\Software\ODBC\ODBC.INI\Powersoft Demo DB V6\PWD = "sql"
  19. HKCU\Software\ODBC\ODBC.INI\Powersoft Demo DB V6\Start =
  20. "<install2>\dbeng50.exe -d -c512"
  21. HKCU\Software\ODBC\ODBC.INI\Powersoft Demo DB V6\UID = "dba"
  22. where <install1> is location of PowerBuilder Install:
  23. The value of <install1> and <install2> can be found in
  24. HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\PB60.EXE\Path =
  25. "<install1>;...;...;<install2>;"
  26. History:
  27. 03/29/2001 bklamik Created
  28. */
  29. #include "precomp.h"
  30. #include <stdio.h>
  31. IMPLEMENT_SHIM_BEGIN(PowerBuilder)
  32. #include "ShimHookMacro.h"
  33. APIHOOK_ENUM_BEGIN
  34. APIHOOK_ENUM_ENTRY(RegQueryValueExA)
  35. APIHOOK_ENUM_ENTRY(RegQueryValueExW)
  36. APIHOOK_ENUM_END
  37. void FixupPowerBuilder()
  38. {
  39. DWORD dwPresent = REG_OPENED_EXISTING_KEY;
  40. HKEY hODBC;
  41. if( ERROR_SUCCESS == RegCreateKeyExW( HKEY_CURRENT_USER,
  42. L"SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources",
  43. 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hODBC, &dwPresent ) )
  44. {
  45. WCHAR c;
  46. DWORD dwLen = 0;
  47. DWORD dwType;
  48. if( REG_CREATED_NEW_KEY == dwPresent ||
  49. ERROR_MORE_DATA != RegQueryValueExW( hODBC,
  50. L"Powersoft Demo DB V6", 0, &dwType,
  51. (BYTE*)&c, &dwLen ) )
  52. {
  53. const WCHAR szVal9[] = L"Sybase SQL Anywhere 5.0";
  54. RegSetValueExW( hODBC, L"Powersoft Demo DB V6",
  55. 0, REG_SZ, (const BYTE*)szVal9, sizeof(szVal9) );
  56. // Find <install1> and <install2>
  57. HKEY hAppPath;
  58. if( ERROR_SUCCESS == RegOpenKeyExW( HKEY_LOCAL_MACHINE,
  59. L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\PB60.EXE",
  60. 0, KEY_READ, &hAppPath ) )
  61. {
  62. WCHAR szValue[ 4 * (MAX_PATH + 1) ] = L"";
  63. DWORD dwSize = sizeof( szValue );
  64. if( ERROR_SUCCESS == RegQueryValueExW( hAppPath, L"path", NULL,
  65. &dwType, (LPBYTE)szValue, &dwSize ) )
  66. {
  67. const WCHAR* szInstall1 = szValue;
  68. const WCHAR* szInstall2;
  69. WCHAR* pFindSemi = szValue;
  70. INT iSemis( 4 );
  71. do
  72. {
  73. while( *pFindSemi != ';' && *pFindSemi != 0 )
  74. {
  75. ++pFindSemi;
  76. }
  77. *pFindSemi = 0;
  78. ++pFindSemi;
  79. if( 2 == iSemis )
  80. {
  81. szInstall2 = pFindSemi;
  82. }
  83. } while( --iSemis != 0 );
  84. HKEY hDemoDB;
  85. dwPresent = REG_OPENED_EXISTING_KEY;
  86. if( ERROR_SUCCESS == RegCreateKeyExW( HKEY_CURRENT_USER,
  87. L"SOFTWARE\\ODBC\\ODBC.INI\\Powersoft Demo DB V6",
  88. 0, NULL, 0, KEY_WRITE, NULL, &hDemoDB, &dwPresent ) )
  89. {
  90. if( REG_CREATED_NEW_KEY == dwPresent )
  91. {
  92. const WCHAR szVal0[] = L"psDemoDB";
  93. const WCHAR szVal1[] = L"sql";
  94. const WCHAR szVal2[] = L"dba";
  95. RegSetValueExW( hDemoDB, L"DataBaseName",
  96. 0, REG_SZ, (const BYTE*)szVal0, sizeof(szVal0) );
  97. RegSetValueExW( hDemoDB, L"PWD",
  98. 0, REG_SZ, (const BYTE*)szVal1, sizeof(szVal1) );
  99. RegSetValueExW( hDemoDB, L"UID",
  100. 0, REG_SZ, (const BYTE*)szVal2, sizeof(szVal2) );
  101. WCHAR szTemp[ MAX_PATH + 1 ];
  102. StringCchCopyW(szTemp, MAX_PATH+1, szInstall1 );
  103. StringCchCatW(szTemp, MAX_PATH+1, L"\\demodb\\psDemoDB.db" );
  104. RegSetValueExW( hDemoDB, L"DataBaseFile",
  105. 0, REG_SZ, (const BYTE*)szTemp,
  106. (lstrlen( szTemp ) + 1) * sizeof(WCHAR) );
  107. StringCchCopyW(szTemp, MAX_PATH+1, szInstall2 );
  108. StringCchCatW(szTemp, MAX_PATH+1, L"\\WOD50T.DLL" );
  109. RegSetValueExW( hDemoDB, L"Driver",
  110. 0, REG_SZ, (const BYTE*)szTemp,
  111. (lstrlen( szTemp ) + 1) * sizeof(WCHAR) );
  112. StringCchCopyW(szTemp, MAX_PATH+1, szInstall2 );
  113. StringCchCatW(szTemp, MAX_PATH+1, L"\\dbeng50.exe -d -c512" );
  114. RegSetValueExW( hDemoDB, L"Start",
  115. 0, REG_SZ, (const BYTE*)szTemp,
  116. (lstrlen( szTemp ) + 1) * sizeof(WCHAR) );
  117. }
  118. RegCloseKey( hDemoDB );
  119. }
  120. }
  121. RegCloseKey( hAppPath );
  122. }
  123. }
  124. RegCloseKey( hODBC );
  125. }
  126. }
  127. LONG
  128. APIHOOK(RegQueryValueExA)(HKEY hKey, LPCSTR lpValueName,
  129. LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData,
  130. LPDWORD lpcbData )
  131. {
  132. FixupPowerBuilder();
  133. return ORIGINAL_API(RegQueryValueExA)(hKey, lpValueName,
  134. lpReserved, lpType, lpData, lpcbData);
  135. }
  136. LONG
  137. APIHOOK(RegQueryValueExW)(HKEY hKey, LPCWSTR lpValueName,
  138. LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData,
  139. LPDWORD lpcbData )
  140. {
  141. FixupPowerBuilder();
  142. return ORIGINAL_API(RegQueryValueExW)(hKey, lpValueName,
  143. lpReserved, lpType, lpData, lpcbData);
  144. }
  145. BOOL
  146. NOTIFY_FUNCTION(
  147. DWORD fdwReason
  148. )
  149. {
  150. if (fdwReason == DLL_PROCESS_ATTACH) {
  151. OSVERSIONINFOEX osvi = {0};
  152. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  153. if (GetVersionEx((OSVERSIONINFO*)&osvi)) {
  154. if (!((VER_SUITE_TERMINAL & osvi.wSuiteMask) &&
  155. !(VER_SUITE_SINGLEUSERTS & osvi.wSuiteMask))) {
  156. //
  157. // Only install hooks if we are not on a "Terminal Server"
  158. // (aka "Application Server") machine.
  159. //
  160. APIHOOK_ENTRY(ADVAPI32.DLL, RegQueryValueExA)
  161. APIHOOK_ENTRY(ADVAPI32.DLL, RegQueryValueExW)
  162. }
  163. }
  164. }
  165. return TRUE;
  166. }
  167. HOOK_BEGIN
  168. CALL_NOTIFY_FUNCTION
  169. HOOK_END
  170. IMPLEMENT_SHIM_END