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.

323 lines
9.2 KiB

  1. #include <windows.h>
  2. #include <userenv.h>
  3. #include <userenvp.h>
  4. #include <shlwapi.h>
  5. #include "shmgdefs.h"
  6. enum {
  7. CMD_W95_TO_SUR,
  8. CMD_DAYTONA_CURSORS,
  9. CMD_FIX_CURSOR_PATHS,
  10. CMD_FIX_SPECIAL_FOLDERS,
  11. CMD_FIX_WINDOWS_PROFILE_SECURITY,
  12. CMD_FIX_USER_PROFILE_SECURITY,
  13. CMD_FIX_POLICIES_SECURITY,
  14. CMD_CVT_SCHEMES_TO_MULTIUSER,
  15. CMD_UPGRADE_NT4_PROFILE_TO_NT5,
  16. CMD_UPGRADE_SCHEMES_AND_NCMETRICS_TO_WIN2000,
  17. CMD_UPGRADE_SCHEMES_AND_NCMETRICS_FROM_WIN9X_TO_WIN2000,
  18. CMD_FIX_CAPI_DIR_ATTRIBUTES,
  19. CMD_MERGE_DESKTOP_AND_NORMAL_STREAMS,
  20. CMD_MOVE_AND_ADJUST_ICON_METRICS,
  21. CMD_FIX_HTML_HELP,
  22. CMD_SET_SCREENSAVER_FRIENDLYUI,
  23. CMD_OCINSTALL_FIXUP,
  24. // enums from here down will run within OleInitialize/OleUnitialize
  25. CMD_OLE_REQUIRED_START = 10000,
  26. CMD_OCINSTALL_SHOW_IE,
  27. CMD_OCINSTALL_REINSTALL_IE,
  28. CMD_OCINSTALL_HIDE_IE,
  29. CMD_OCINSTALL_USER_CONFIG_IE,
  30. CMD_OCINSTALL_SHOW_OE,
  31. CMD_OCINSTALL_REINSTALL_OE,
  32. CMD_OCINSTALL_HIDE_OE,
  33. CMD_OCINSTALL_USER_CONFIG_OE,
  34. CMD_OCINSTALL_SHOW_VM,
  35. CMD_OCINSTALL_REINSTALL_VM,
  36. CMD_OCINSTALL_HIDE_VM,
  37. } CMD_VALS;
  38. int mystrcpy( LPTSTR pszOut, LPTSTR pszIn, TCHAR chTerm ) {
  39. BOOL fInQuote = FALSE;
  40. LPTSTR pszStrt = pszOut;
  41. while( *pszIn && !fInQuote && *pszIn != chTerm ) {
  42. if (*pszIn == TEXT('"')) {
  43. fInQuote = !fInQuote;
  44. }
  45. *pszOut++ = *pszIn++;
  46. }
  47. *pszOut = TEXT('\0');
  48. return (int)(pszOut - pszStrt);
  49. }
  50. BOOL HasPath( LPTSTR pszFilename ) {
  51. //
  52. // Special case null string so it won't get changed
  53. //
  54. if (*pszFilename == TEXT('\0'))
  55. return TRUE;
  56. for(; *pszFilename; pszFilename++ ) {
  57. if (*pszFilename == TEXT(':') || *pszFilename == TEXT('\\') || *pszFilename == TEXT('/')) {
  58. return TRUE;
  59. }
  60. }
  61. return FALSE;
  62. }
  63. void HandOffToShell32 (LPCSTR pcszCommand, LPCSTR pcszOptionalArgument)
  64. {
  65. HINSTANCE hInstShell32 = LoadLibrary(TEXT("shell32"));
  66. if (hInstShell32 != NULL)
  67. {
  68. typedef HRESULT (*PFNFirstUserLogon) (LPCSTR pcszCommand, LPCSTR pcszOptionalArgument);
  69. PFNFirstUserLogon pfnFirstUserLogon;
  70. // Call shell32!FirstUserLogon which is Ordinal230 defined in shell32.src.
  71. pfnFirstUserLogon = (PFNFirstUserLogon)GetProcAddress(hInstShell32, (LPCSTR)MAKEINTRESOURCE(230));
  72. if (pfnFirstUserLogon != NULL)
  73. pfnFirstUserLogon(pcszCommand, pcszOptionalArgument);
  74. FreeLibrary(hInstShell32);
  75. }
  76. }
  77. /*
  78. * Command Parser
  79. */
  80. typedef struct {
  81. LPSTR pszCmd;
  82. int idCmd;
  83. } CMD;
  84. CMD aCmds[] = {
  85. { "W", CMD_W95_TO_SUR },
  86. { "Cvt-Curs", CMD_DAYTONA_CURSORS },
  87. { "Fix-Curs", CMD_FIX_CURSOR_PATHS },
  88. { "Fix-Folders", CMD_FIX_SPECIAL_FOLDERS},
  89. { "Fix-Win-Security", CMD_FIX_WINDOWS_PROFILE_SECURITY},
  90. { "Fix-User-Security", CMD_FIX_USER_PROFILE_SECURITY},
  91. { "Fix-Policies-Security", CMD_FIX_POLICIES_SECURITY},
  92. { "Cvt-Mouse-Schemes", CMD_CVT_SCHEMES_TO_MULTIUSER},
  93. { "UpgradeProfileNT4ToNT5", CMD_UPGRADE_NT4_PROFILE_TO_NT5},
  94. { "UpgradeSchemesAndNcMetricsToWin2000", CMD_UPGRADE_SCHEMES_AND_NCMETRICS_TO_WIN2000},
  95. { "UpgradeSchemesAndNcMetricsFromWin9xToWin2000", CMD_UPGRADE_SCHEMES_AND_NCMETRICS_FROM_WIN9X_TO_WIN2000},
  96. { "FixCAPIDirAttrib", CMD_FIX_CAPI_DIR_ATTRIBUTES},
  97. { "MergeDesktopAndNormalStreams", CMD_MERGE_DESKTOP_AND_NORMAL_STREAMS },
  98. { "MoveAndAdjustIconMetrics", CMD_MOVE_AND_ADJUST_ICON_METRICS },
  99. { "Fix-HTML-Help", CMD_FIX_HTML_HELP },
  100. { "Set-Screensaver-On-FriendlyUI", CMD_SET_SCREENSAVER_FRIENDLYUI },
  101. { "OCInstallShowIE", CMD_OCINSTALL_SHOW_IE },
  102. { "OCInstallReinstallIE", CMD_OCINSTALL_REINSTALL_IE },
  103. { "OCInstallHideIE", CMD_OCINSTALL_HIDE_IE },
  104. { "OCInstallUserConfigIE", CMD_OCINSTALL_USER_CONFIG_IE },
  105. { "OCInstallShowOE", CMD_OCINSTALL_SHOW_OE },
  106. { "OCInstallReinstallOE", CMD_OCINSTALL_REINSTALL_OE },
  107. { "OCInstallHideOE", CMD_OCINSTALL_HIDE_OE },
  108. { "OCInstallUserConfigOE", CMD_OCINSTALL_USER_CONFIG_OE },
  109. // { "OCInstallShowVM", CMD_OCINSTALL_SHOW_VM },
  110. { "OCInstallReinstallVM", CMD_OCINSTALL_REINSTALL_VM },
  111. // { "OCInstallHideVM", CMD_OCINSTALL_HIDE_VM },
  112. { "OCInstallFixup", CMD_OCINSTALL_FIXUP },
  113. };
  114. #define C_CMDS ARRAYSIZE(aCmds)
  115. void __cdecl main( int cArgs, char **szArg) {
  116. int i;
  117. HRESULT hrOle = E_FAIL;
  118. SHMGLogErrMsg("main called with args", (DWORD)cArgs);
  119. if (cArgs < 2 || cArgs > 3)
  120. ExitProcess(1);
  121. #ifdef SHMG_DBG
  122. for(i=1; i<cArgs; i++)
  123. SHMGLogErrMsg(szArg[i], (DWORD)i);
  124. #endif
  125. for( i = 0; i < C_CMDS && lstrcmpA( szArg[1], aCmds[i].pszCmd ) != 0; i++ );
  126. if (i >= C_CMDS)
  127. ExitProcess(1);
  128. if (aCmds[i].idCmd >= CMD_OLE_REQUIRED_START)
  129. {
  130. hrOle = OleInitialize(NULL);
  131. if (FAILED(hrOle))
  132. {
  133. ExitProcess(1);
  134. }
  135. }
  136. switch( aCmds[i].idCmd ) {
  137. case CMD_W95_TO_SUR:
  138. CvtDeskCPL_Win95ToSUR();
  139. break;
  140. case CMD_DAYTONA_CURSORS:
  141. CvtCursorsCPL_DaytonaToSUR();
  142. break;
  143. case CMD_FIX_CURSOR_PATHS:
  144. FixupCursorSchemePaths();
  145. break;
  146. case CMD_FIX_SPECIAL_FOLDERS:
  147. ResetUserSpecialFolderPaths();
  148. break;
  149. case CMD_FIX_WINDOWS_PROFILE_SECURITY:
  150. ASSERT(FALSE); // no longer supported
  151. break;
  152. case CMD_FIX_USER_PROFILE_SECURITY:
  153. FixUserProfileSecurity();
  154. break;
  155. case CMD_FIX_POLICIES_SECURITY:
  156. FixPoliciesSecurity();
  157. break;
  158. case CMD_CVT_SCHEMES_TO_MULTIUSER:
  159. CvtCursorSchemesToMultiuser();
  160. break;
  161. case CMD_UPGRADE_NT4_PROFILE_TO_NT5:
  162. MigrateNT4ToNT5();
  163. break;
  164. case CMD_UPGRADE_SCHEMES_AND_NCMETRICS_TO_WIN2000:
  165. UpgradeSchemesAndNcMetricsToWin2000();
  166. break;
  167. case CMD_UPGRADE_SCHEMES_AND_NCMETRICS_FROM_WIN9X_TO_WIN2000:
  168. UpgradeSchemesAndNcMetricsFromWin9xToWin2000(cArgs > 2 ? szArg[2] : NULL);
  169. break;
  170. case CMD_FIX_CAPI_DIR_ATTRIBUTES:
  171. SetSystemBitOnCAPIDir();
  172. break;
  173. case CMD_MERGE_DESKTOP_AND_NORMAL_STREAMS:
  174. case CMD_MOVE_AND_ADJUST_ICON_METRICS:
  175. HandOffToShell32(szArg[1], cArgs > 2 ? szArg[2] : NULL);
  176. break;
  177. case CMD_FIX_HTML_HELP:
  178. FixHtmlHelp();
  179. break;
  180. case CMD_SET_SCREENSAVER_FRIENDLYUI:
  181. SetScreensaverOnFriendlyUI();
  182. break;
  183. case CMD_OCINSTALL_FIXUP:
  184. FixupOptionalComponents();
  185. break;
  186. case CMD_OCINSTALL_SHOW_IE:
  187. ShowHideIE(TRUE, FALSE, TRUE);
  188. break;
  189. case CMD_OCINSTALL_REINSTALL_IE:
  190. ShowHideIE(TRUE, TRUE, TRUE);
  191. break;
  192. case CMD_OCINSTALL_HIDE_IE:
  193. ShowHideIE(FALSE, FALSE, TRUE);
  194. break;
  195. case CMD_OCINSTALL_USER_CONFIG_IE:
  196. UserConfigIE();
  197. break;
  198. case CMD_OCINSTALL_SHOW_OE:
  199. ShowHideOE(TRUE, FALSE, TRUE);
  200. break;
  201. case CMD_OCINSTALL_REINSTALL_OE:
  202. ShowHideOE(TRUE, TRUE, TRUE);
  203. break;
  204. case CMD_OCINSTALL_HIDE_OE:
  205. ShowHideOE(FALSE, FALSE, TRUE);
  206. break;
  207. case CMD_OCINSTALL_USER_CONFIG_OE:
  208. UserConfigOE();
  209. break;
  210. case CMD_OCINSTALL_SHOW_VM:
  211. // Do nothing...
  212. break;
  213. case CMD_OCINSTALL_REINSTALL_VM:
  214. ReinstallVM();
  215. break;
  216. case CMD_OCINSTALL_HIDE_VM:
  217. // Do nothing...
  218. break;
  219. default:
  220. ExitProcess(2);
  221. }
  222. if (SUCCEEDED(hrOle))
  223. {
  224. OleUninitialize();
  225. }
  226. ExitProcess(0);
  227. }
  228. #ifdef SHMG_DBG
  229. /***************************************************************************\
  230. *
  231. * FUNCTION: FmtSprintf( DWORD id, ... );
  232. *
  233. * PURPOSE: sprintf but it gets the pattern string from the message rc.
  234. *
  235. * History:
  236. * 03-May-1993 JonPa Created it.
  237. \***************************************************************************/
  238. TCHAR g_szDbgBuffer[16384];
  239. char g_szDbgBufA[16384];
  240. void Dprintf( LPTSTR pszFmt, ... ) {
  241. DWORD cb;
  242. LPVOID psz = g_szDbgBuffer;
  243. va_list marker;
  244. va_start( marker, pszFmt );
  245. StringCchVPrintf(g_szDbgBuffer, ARRAYSIZE(g_szDbgBuffer), pszFmt, marker);
  246. OutputDebugString(g_szDbgBuffer);
  247. #ifdef UNICODE
  248. cb = WideCharToMultiByte(CP_ACP, 0, g_szDbgBuffer, -1, g_szDbgBufA, sizeof(g_szDbgBufA), NULL, NULL);
  249. psz = g_szDbgBufA;
  250. #else
  251. cb = lstrlen(g_szDbgBuffer) * sizeof(TCHAR);
  252. #endif
  253. WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), psz, cb, &cb, NULL);
  254. va_end( marker );
  255. }
  256. #endif