Source code of Windows XP (NT5)
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.

172 lines
5.8 KiB

  1. //=======================================================================
  2. // Microsoft state migration helper tool
  3. //
  4. // Copyright Microsoft (c) 2000 Microsoft Corporation.
  5. //
  6. // File: common.hxx
  7. //
  8. //=======================================================================
  9. #ifndef COMMON_HXX
  10. #define COMMON_HXX
  11. // These 4 headers must be included in this order.
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <nturtl.h>
  15. #include <windows.h>
  16. #include <setupapi.h>
  17. #include <resource.h>
  18. //---------------------------------------------------------------
  19. // Macros
  20. // This macro jumps to the label cleanup if result is not ERROR_SUCCESS.
  21. #define FAIL_ON_ERROR( result ) \
  22. if (result != ERROR_SUCCESS) goto cleanup;
  23. // This macro writes a message to the log file and jumps to the
  24. // label cleanup if result is not ERROR_SUCCESS.
  25. #define LOG_ASSERT( result ) \
  26. if ((result) != ERROR_SUCCESS) \
  27. { \
  28. Win32PrintfResource( LogFile, ResultToRC( result ) ); \
  29. if (DebugOutput) \
  30. { \
  31. Win32Printf(LogFile, \
  32. "%s [%d] return value was: %d\r\n", \
  33. TEXT(__FILE__), __LINE__, (result)); \
  34. } \
  35. goto cleanup; \
  36. }
  37. // This macro writes a specified message to the log file, sets result
  38. // to a specified error, and jumps to the label cleanup if the
  39. // expression is not true.
  40. #define LOG_ASSERT_EXPR( expr, rc, result, error ) \
  41. if (!(expr)) \
  42. { \
  43. Win32PrintfResource( LogFile, (rc) ); \
  44. (result) = (error); \
  45. if (DebugOutput) \
  46. { \
  47. Win32Printf(LogFile, \
  48. "%s [%d] expr value was: %d\r\n", \
  49. TEXT(__FILE__), __LINE__, (result)); \
  50. } \
  51. goto cleanup; \
  52. }
  53. // This macro writes a message to the log file, and sets the result to
  54. // the last error if success is not true.
  55. #define LOG_ASSERT_GLE( success, result ) \
  56. if (!(success)) \
  57. { \
  58. (result) = GetLastError(); \
  59. Win32PrintfResource( LogFile, ResultToRC( result ) ); \
  60. if (DebugOutput) \
  61. { \
  62. Win32Printf(LogFile, \
  63. "%s [%d] return value was: %d\r\n", \
  64. TEXT(__FILE__), __LINE__, (result)); \
  65. } \
  66. goto cleanup; \
  67. }
  68. #if DBG == 1
  69. #define DEBUG_ASSERT( expr ) \
  70. if (!(expr)) \
  71. if (PopupError( #expr, __FILE__, __LINE__ ) != IDOK) \
  72. DebugBreak();
  73. #else
  74. #define DEBUG_ASSERT( expr )
  75. #endif
  76. //---------------------------------------------------------------
  77. // Types
  78. typedef DWORD
  79. (*MRtlConvertSidToUnicodeString)(
  80. PUNICODE_STRING UnicodeString,
  81. PSID Sid,
  82. BOOLEAN AllocateDestinationString
  83. );
  84. typedef void
  85. (*MRtlInitUnicodeString)(
  86. PUNICODE_STRING DestinationString,
  87. PCWSTR SourceString
  88. );
  89. typedef void
  90. (*MRtlFreeUnicodeString)(
  91. PUNICODE_STRING UnicodeString
  92. );
  93. typedef BOOL
  94. (*MDuplicateTokenEx)(
  95. IN HANDLE hExistingToken,
  96. IN DWORD dwDesiredAccess,
  97. IN LPSECURITY_ATTRIBUTES lpTokenAttributes,
  98. IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
  99. IN TOKEN_TYPE TokenType,
  100. OUT PHANDLE phNewToken);
  101. //---------------------------------------------------------------
  102. // External globals
  103. extern HANDLE Console;
  104. extern BOOL CopyFiles;
  105. extern BOOL CopySystem;
  106. extern BOOL CopyUser;
  107. extern HKEY CurrentUser;
  108. extern BOOL DebugOutput;
  109. extern BOOL ExcludeByDefault;
  110. extern HINF InputInf;
  111. extern HANDLE LogFile;
  112. extern char *MigrationPath;
  113. extern WCHAR wcsMigrationPath[];
  114. extern BOOL OutputAnsi;
  115. extern HANDLE OutputFile;
  116. extern BOOL ReallyCopyFiles;
  117. extern BOOL SchedSystem;
  118. extern BOOL TestMode;
  119. extern BOOL UserPortion;
  120. extern BOOL Verbose;
  121. extern BOOL VerboseReg;
  122. extern BOOL Win9x;
  123. extern HANDLE STDERR;
  124. extern MRtlConvertSidToUnicodeString GRtlConvertSidToUnicodeString;
  125. extern MRtlInitUnicodeString GRtlInitUnicodeString;
  126. extern MRtlFreeUnicodeString GRtlFreeUnicodeString;
  127. extern MDuplicateTokenEx GDuplicateTokenEx;
  128. //---------------------------------------------------------------
  129. // Prototypes
  130. DWORD EnableBackupPrivilege( void );
  131. DWORD OpenFiles ( void );
  132. void CloseFiles ( void );
  133. DWORD MakeUnicode ( char *buffer, WCHAR **wbuffer );
  134. DWORD NtImports ( void );
  135. DWORD OpenInf ( char *file );
  136. BOOL PopupError ( char *expr, char *file, DWORD line );
  137. void PrintHelp ( BOOL scan );
  138. DWORD ResultToRC ( DWORD result );
  139. DWORD Win32Printf ( HANDLE file, char *format, ... );
  140. DWORD Win32PrintfResourceA ( HANDLE file, DWORD resource_id, ... );
  141. DWORD Win32PrintfResourceW ( HANDLE file, DWORD resource_id, ... );
  142. #ifdef UNICODE
  143. #define Win32PrintfResource Win32PrintfResourceW
  144. #else
  145. #define Win32PrintfResource Win32PrintfResourceA
  146. #endif
  147. #endif // COMMON_HXX