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.

157 lines
3.9 KiB

  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include "regdiff.h"
  4. #define SIZEOFARRAY(a) (sizeof (a) / sizeof (a[0]))
  5. #define CHARS(text) (SIZEOFARRAY(text)-1)
  6. typedef
  7. INT
  8. (*PFNUPDATE2_CALL_PROTOTYPE) (
  9. IN INT Argc,
  10. IN TCHAR* Argv[]
  11. );
  12. BOOL
  13. pGetUserProfileDir (
  14. OUT PTSTR Path,
  15. IN DWORD BufChars
  16. )
  17. {
  18. BOOL b = FALSE;
  19. // HANDLE token = NULL;
  20. if (ExpandEnvironmentStrings (TEXT("%USERPROFILE%"), Path, BufChars)) {
  21. b = TRUE;
  22. } else {
  23. /*
  24. if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &token)) {
  25. rc = GetLastError ();
  26. __leave;
  27. }
  28. if (!GetUserProfileDirectory (token, Path, &BufChars)) {
  29. rc = GetLastError ();
  30. __leave;
  31. }
  32. if (token) {
  33. CloseHandle (token);
  34. }
  35. */
  36. }
  37. return b;
  38. }
  39. INT
  40. ApplyDefUserChanges (
  41. IN INT Argc,
  42. IN TCHAR* Argv[]
  43. )
  44. {
  45. BOOL b = FALSE;
  46. DWORD rc = ERROR_SUCCESS;
  47. PFNINSTALLDIFFERENCES pfnInstallUserDiff;
  48. TCHAR fileUserDiff[MAX_PATH];
  49. TCHAR fileUserUndo[MAX_PATH];
  50. HMODULE hLibrary = LoadLibrary (TEXT("regdiff.dll"));
  51. if (!hLibrary) {
  52. return GetLastError ();
  53. }
  54. __try {
  55. pfnInstallUserDiff = (PFNINSTALLDIFFERENCES) GetProcAddress (hLibrary, "InstallDifferences");
  56. if (!pfnInstallUserDiff) {
  57. __leave;
  58. }
  59. if (!GetSystemDirectory (fileUserDiff, MAX_PATH)) {
  60. __leave;
  61. }
  62. lstrcat (fileUserDiff, TEXT("\\userdiff.rdf"));
  63. if (GetFileAttributes (fileUserDiff) == ~0) {
  64. __leave;
  65. }
  66. if (!pGetUserProfileDir (fileUserUndo, MAX_PATH)) {
  67. __leave;
  68. }
  69. lstrcat (fileUserUndo, TEXT("\\userundo.rdf"));
  70. if (!pfnInstallUserDiff (fileUserDiff, fileUserUndo)) {
  71. __leave;
  72. }
  73. b = TRUE;
  74. }
  75. __finally {
  76. rc = b ? ERROR_SUCCESS : GetLastError ();
  77. FreeLibrary (hLibrary);
  78. }
  79. return rc;
  80. }
  81. INT
  82. __cdecl
  83. _tmain (
  84. IN INT Argc,
  85. IN TCHAR* Argv[]
  86. )
  87. {
  88. INT i;
  89. PCTSTR szModuleName = NULL;
  90. PCSTR procName = NULL;
  91. HMODULE hLibrary = NULL;
  92. PFNUPDATE2_CALL_PROTOTYPE proc = NULL;
  93. INT result = ERROR_INVALID_PARAMETER;
  94. //
  95. // Scan Command Line
  96. //
  97. for (i = 1; i < Argc; i++) {
  98. if (Argv[i][0] == TEXT('-') || Argv[i][0] == TEXT('/')) {
  99. if (!_tcsnicmp (&Argv[i][1], TEXT("spsetup"), CHARS(TEXT("spsetup")))) {
  100. if (Argv[i][1 + CHARS(TEXT("spsetup"))] == 0) {
  101. szModuleName = TEXT("spsetup.dll");
  102. } else if (Argv[i][1 + CHARS(TEXT("spsetup"))] == TEXT(':')) {
  103. szModuleName = &Argv[i][1 + CHARS(TEXT("spsetup:"))];
  104. } else {
  105. return result;
  106. }
  107. procName = "SpsInstallServicePack";
  108. } else if (!_tcsnicmp (&Argv[i][1], TEXT("user"), CHARS(TEXT("user")))) {
  109. proc = ApplyDefUserChanges;
  110. break;
  111. } else {
  112. return result;
  113. }
  114. }
  115. }
  116. //
  117. // Load the Appropriate Libary and function pointer
  118. //
  119. if (procName && szModuleName && !proc) {
  120. hLibrary = LoadLibrary (szModuleName);
  121. if (hLibrary) {
  122. //
  123. // Call the target function.
  124. //
  125. proc = (PFNUPDATE2_CALL_PROTOTYPE) GetProcAddress (hLibrary, procName);
  126. if (proc) {
  127. result = proc (Argc, Argv);
  128. }
  129. //
  130. // done with the library
  131. //
  132. FreeLibrary (hLibrary);
  133. }
  134. } else if (proc && !procName && !szModuleName) {
  135. result = proc (Argc, Argv);
  136. }
  137. return result;
  138. }