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.

284 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. xml-jet.cpp
  5. Abstract:
  6. Command line tool for exporting SCE anaylsis data from an
  7. SCE JET Database to XML
  8. Author:
  9. Steven Chan (t-schan) July 2002
  10. --*/
  11. //
  12. // System header files
  13. //
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <windows.h>
  18. #include <string.h>
  19. #include <shlwapi.h>
  20. #include <winnlsp.h>
  21. #include <sddl.h>
  22. //
  23. // COM/XML header files
  24. //
  25. #include <atlbase.h>
  26. #include <objbase.h>
  27. //
  28. // CRT header files
  29. //
  30. #include <process.h>
  31. #include <wchar.h>
  32. #include <stddef.h>
  33. #include <stdlib.h>
  34. #include <iostream.h>
  35. #include <stdio.h>
  36. #include <time.h>
  37. #include <limits.h>
  38. #include <io.h>
  39. #include <locale.h>
  40. #include "resource.h"
  41. #include "SecMan.h"
  42. #define STRING_BUFFER_SIZE 512
  43. WCHAR szTmpStringBuffer[STRING_BUFFER_SIZE];
  44. HMODULE myModuleHandle;
  45. void printIDS(IN UINT uID);
  46. void
  47. __cdecl wmain(
  48. int argc,
  49. WCHAR * argv[]
  50. )
  51. /*++
  52. Routine Description:
  53. Main routine of the SCE/JET to XML executable
  54. Opens the specified .sdb file, reads the logged System Values and
  55. Baseline Values from the .sdb file, then uses the SecLogger class to
  56. format log these results. Currently SecLogger logs to XML.
  57. Usage:
  58. <exename> infilename outfilename
  59. infilename: The filename of the .sdb database to be opened
  60. outfilename: The filename of the generated (XML) log file
  61. Return Value:
  62. none
  63. --*/
  64. {
  65. WCHAR szInFile[_MAX_PATH];
  66. WCHAR szOutFile[_MAX_PATH];
  67. WCHAR szErrLogFile[_MAX_PATH];
  68. myModuleHandle=GetModuleHandle(NULL);
  69. //
  70. // call SetThreadUILanguage() indirectly for win2k compatability
  71. //
  72. typedef void (CALLBACK* LPFNSETTHREADUILANGUAGE)();
  73. typedef void (CALLBACK* LPFNSETTHREADUILANGUAGE2)(DWORD);
  74. HMODULE hKern32; // Handle to Kernel32 dll
  75. LPFNSETTHREADUILANGUAGE lpfnSetThreadUILanguage; // Function pointer
  76. hKern32 = LoadLibrary(L"kernel32.dll");
  77. if (hKern32 != NULL)
  78. {
  79. lpfnSetThreadUILanguage = (LPFNSETTHREADUILANGUAGE) GetProcAddress(hKern32,
  80. "SetThreadUILanguage");
  81. if (!lpfnSetThreadUILanguage)
  82. {
  83. FreeLibrary(hKern32);
  84. }
  85. else
  86. {
  87. // call the function
  88. lpfnSetThreadUILanguage();
  89. }
  90. }
  91. //
  92. // Check that Command Line args are valid
  93. //
  94. printIDS(IDS_PROGRAM_INFO);
  95. if ((argc!=3)&&(argc!=4)) { // progname src dest
  96. //
  97. // arg count wrong; output usage
  98. //
  99. printIDS(IDS_PROGRAM_USAGE_0);
  100. wprintf(argv[0]); // print progname
  101. printIDS(IDS_PROGRAM_USAGE_1);
  102. return; // quit
  103. }
  104. // convert filenames to full pathnames
  105. _wfullpath(szInFile, argv[1], _MAX_PATH);
  106. _wfullpath(szOutFile, argv[2], _MAX_PATH);
  107. // load security database interface
  108. CoInitialize(NULL);
  109. CComPtr<ISecurityDatabase> SecDB;
  110. HRESULT hr = SecDB.CoCreateInstance(__uuidof(SecurityDatabase));
  111. switch(hr) {
  112. case S_OK:
  113. printIDS(IDS_SECMAN_INIT);
  114. break;
  115. case REGDB_E_CLASSNOTREG:
  116. printIDS(IDS_ERROR_CLASSNOTREG);
  117. break;
  118. case CLASS_E_NOAGGREGATION:
  119. printIDS(IDS_ERROR_NOAGGREGATION);
  120. break;
  121. case E_NOINTERFACE:
  122. printIDS(IDS_ERROR_NOINTERFACE);
  123. break;
  124. default:
  125. printIDS(IDS_ERROR_UNEXPECTED);
  126. break;
  127. }
  128. // set database filename
  129. if (SUCCEEDED(hr)) {
  130. hr=SecDB->put_FileName(CComBSTR(szInFile));
  131. switch(hr) {
  132. case S_OK:
  133. break;
  134. case E_INVALIDARG:
  135. printIDS(IDS_ERROR_INVALIDFILENAME);
  136. break;
  137. case E_OUTOFMEMORY:
  138. printIDS(IDS_ERROR_OUTOFMEMORY);
  139. break;
  140. }
  141. }
  142. // export analysis
  143. if (SUCCEEDED(hr)) {
  144. if (argc==4) {
  145. _wfullpath(szErrLogFile, argv[3], _MAX_PATH);
  146. hr=SecDB->ExportAnalysisToXML(CComBSTR(szOutFile), CComBSTR(szErrLogFile));
  147. } else {
  148. hr=SecDB->ExportAnalysisToXML(CComBSTR(szOutFile), NULL);
  149. }
  150. switch(hr) {
  151. case S_OK:
  152. printIDS(IDS_PROGRAM_SUCCESS);
  153. wprintf(szOutFile);
  154. wprintf(L"\n\r");
  155. break;
  156. case ERROR_OLD_WIN_VERSION:
  157. printIDS(IDS_ERROR_OLDWINVERSION);
  158. break;
  159. case ERROR_MOD_NOT_FOUND:
  160. printIDS(IDS_ERROR_MODNOTFOUND);
  161. break;
  162. case ERROR_WRITE_FAULT:
  163. printIDS(IDS_ERROR_WRITEFAULT);
  164. break;
  165. case ERROR_INVALID_NAME:
  166. printIDS(IDS_ERROR_INVALIDFILENAME);
  167. break;
  168. case E_ACCESSDENIED:
  169. printIDS(IDS_ERROR_ACCESSDENIED);
  170. break;
  171. case ERROR_OPEN_FAILED:
  172. printIDS(IDS_ERROR_OPENFAILED);
  173. break;
  174. case ERROR_FILE_NOT_FOUND:
  175. printIDS(IDS_ERROR_FILENOTFOUND);
  176. break;
  177. case ERROR_READ_FAULT:
  178. printIDS(IDS_ERROR_READFAULT);
  179. break;
  180. case E_OUTOFMEMORY:
  181. printIDS(IDS_ERROR_OUTOFMEMORY);
  182. break;
  183. case E_UNEXPECTED:
  184. default:
  185. printIDS(IDS_ERROR_UNEXPECTED);
  186. break;
  187. }
  188. }
  189. wprintf(L"\n\r");
  190. CoUninitialize();
  191. // SetThreadUILanguage(0);
  192. if (lpfnSetThreadUILanguage)
  193. {
  194. ((LPFNSETTHREADUILANGUAGE2)lpfnSetThreadUILanguage)(0);
  195. }
  196. }
  197. void
  198. printIDS(
  199. IN UINT uID
  200. )
  201. /*++
  202. Routine Description:
  203. Helper function for automating printing of strings from stringtable
  204. Usage:
  205. uID: resource ID of string to be printed
  206. Return Value:
  207. none
  208. --*/
  209. {
  210. LoadString(myModuleHandle,
  211. uID,
  212. szTmpStringBuffer,
  213. STRING_BUFFER_SIZE);
  214. wprintf(szTmpStringBuffer);
  215. }