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.

991 lines
30 KiB

  1. // ===========================================================================
  2. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  3. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  4. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  5. // PARTICULAR PURPOSE.
  6. //
  7. // Copyright 2001 Microsoft Corporation. All Rights Reserved.
  8. // ===========================================================================
  9. /*
  10. WinHTTP Trace Configuration Tool
  11. */
  12. #include <windows.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <fcntl.h>
  16. #include <stdlib.h>
  17. #include <io.h>
  18. #include <wininet.h>
  19. //
  20. // private macros
  21. //
  22. #define REGOPENKEYEX(a, b, c, d, e) RegOpenKeyEx((a), (b), (c), (d), (e))
  23. #define REGCREATEKEYEX(a, b, c, d, e, f, g, h, i) \
  24. RegCreateKeyEx((a), (b), (c), (d), (e), (f), (g), (h), (i))
  25. #define REGCLOSEKEY(a) RegCloseKey(a)
  26. #define CASE_OF(constant) case constant: return # constant
  27. #define BASE_TRACE_KEY HKEY_LOCAL_MACHINE
  28. #define TRACE_ENABLED_VARIABLE_NAME "Enabled"
  29. #define LOG_FILE_PREFIX_VARIABLE_NAME "LogFilePrefix"
  30. #define TO_FILE_OR_DEBUGGER_VARIABLE_NAME "ToFileOrDebugger"
  31. #define SHOWBYTES_VARIABLE_NAME "ShowBytes"
  32. #define SHOWAPITRACE_VARIABLE_NAME "ShowApiTrace"
  33. #define MAXFILESIZE_VARIABLE_NAME "MaxFileSize"
  34. #define MINFILESIZE 65535
  35. #define INTERNET_SETTINGS_KEY "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
  36. #define INTERNET_TRACE_SETTINGS_KEY INTERNET_SETTINGS_KEY "\\WinHttp\\Tracing"
  37. #define SZREGVALUE_MAX 255
  38. #if !defined(max)
  39. #define max(a, b) ((a)<(b)) ? (b) : (a)
  40. #endif
  41. #define OUTPUT_MESSAGE(Member, Value, DefaultValue) if(Value != INVALID_VALUE) \
  42. fprintf(stdout, " " #Member ": %d\n", Value);\
  43. else \
  44. fprintf(stdout, " " #Member " -key not set- (default value: %d)\n", DefaultValue)
  45. #define HANDLE_COMMON_SWITCH(Member, HigherBound) \
  46. argc--; \
  47. argv++; \
  48. \
  49. int Member; \
  50. /* TODO: atoi() will return zero for garbage too: */ \
  51. if (argc == 0 || (((Member = atoi(argv[0])), Member < 0) || Member > HigherBound)) \
  52. { \
  53. Args->Error = true; \
  54. goto Exit; \
  55. } \
  56. else \
  57. { \
  58. Args-> Member = Member; \
  59. }
  60. #define INVALID_VALUE 0xFFFFFFFF
  61. //
  62. // private prototypes
  63. //
  64. LPSTR InternetMapError(DWORD Error);
  65. //
  66. // private functions based on registry.cxx and notifctn.cxx:
  67. //
  68. DWORD
  69. ReadTraceSettingsDwordKey(
  70. IN LPCSTR ParameterName,
  71. OUT LPDWORD ParameterValue
  72. );
  73. DWORD
  74. ReadTraceSettingsStringKey(
  75. IN LPCSTR ParameterName,
  76. OUT LPSTR ParameterValue,
  77. IN OUT LPDWORD ParameterLength
  78. );
  79. DWORD
  80. WriteTraceSettingsDwordKey(
  81. IN LPCSTR ParameterName,
  82. IN DWORD ParameterValue
  83. );
  84. DWORD WriteTraceSettingsStringKey(
  85. IN LPCSTR pszKey,
  86. IN LPSTR pszValue,
  87. IN DWORD dwSize);
  88. struct ARGS
  89. {
  90. bool Error;
  91. DWORD TracingEnabled;
  92. char * FileNamePrefix;
  93. DWORD ToFileOrDebugger;
  94. DWORD ShowBytes;
  95. DWORD ShowApiTrace;
  96. DWORD MaxFileSize;
  97. ARGS() : Error(false), TracingEnabled(INVALID_VALUE), FileNamePrefix(NULL),
  98. ToFileOrDebugger(INVALID_VALUE), ShowBytes(INVALID_VALUE), ShowApiTrace(INVALID_VALUE), MaxFileSize(INVALID_VALUE)
  99. {
  100. }
  101. BOOL operator ==( ARGS &Args2)
  102. {
  103. if((this->Error == Args2.Error) && (this->TracingEnabled == Args2.TracingEnabled) && (this->FileNamePrefix == Args2.FileNamePrefix)
  104. && (this->ToFileOrDebugger == Args2.ToFileOrDebugger) && (this->ShowBytes == Args2.ShowBytes)
  105. && (this->ShowApiTrace == Args2.ShowApiTrace) && (this->MaxFileSize == Args2.MaxFileSize))
  106. return TRUE;
  107. return FALSE;
  108. }
  109. };
  110. void ParseArguments(int argc, char ** argv, ARGS * Args)
  111. {
  112. if (argc == 0)
  113. return;
  114. while (argc && argv[0][0] == '-')
  115. {
  116. switch (tolower(argv[0][1]))
  117. {
  118. default:
  119. Args->Error = true;
  120. goto Exit;
  121. case 'e':
  122. HANDLE_COMMON_SWITCH(TracingEnabled, 1);
  123. break;
  124. case 'd':
  125. HANDLE_COMMON_SWITCH(ToFileOrDebugger, 2);
  126. break;
  127. case 's':
  128. HANDLE_COMMON_SWITCH(ShowBytes, 2);
  129. break;
  130. case 't':
  131. HANDLE_COMMON_SWITCH(ShowApiTrace, 1);
  132. break;
  133. case 'm':
  134. HANDLE_COMMON_SWITCH(MaxFileSize, INVALID_VALUE);
  135. Args->MaxFileSize = max(Args->MaxFileSize, MINFILESIZE);
  136. break;
  137. case 'l':
  138. argc--;
  139. argv++;
  140. if (argc == 0)
  141. {
  142. // error: no filename prefix specified
  143. Args->Error = true;
  144. goto Exit;
  145. }
  146. else
  147. {
  148. Args->FileNamePrefix = argv[0];
  149. if(!strcmp(argv[0], "*"))
  150. // Blank out registry setting
  151. Args->FileNamePrefix = "";
  152. }
  153. break;
  154. }
  155. argv++;
  156. argc--;
  157. }
  158. if (argc > 0)
  159. {
  160. Args->Error = true;
  161. goto Exit;
  162. }
  163. Exit:
  164. return;
  165. }
  166. void SetTraceSettings(ARGS Args)
  167. {
  168. DWORD error;
  169. if((error = WriteTraceSettingsDwordKey(TRACE_ENABLED_VARIABLE_NAME, Args.TracingEnabled) ) == ERROR_SUCCESS
  170. && (error = WriteTraceSettingsStringKey(LOG_FILE_PREFIX_VARIABLE_NAME, Args.FileNamePrefix, Args.FileNamePrefix? strlen(Args.FileNamePrefix) + 1: -1)) == ERROR_SUCCESS
  171. && (error = WriteTraceSettingsDwordKey(TO_FILE_OR_DEBUGGER_VARIABLE_NAME, Args.ToFileOrDebugger)) == ERROR_SUCCESS
  172. && (error = WriteTraceSettingsDwordKey(SHOWBYTES_VARIABLE_NAME, Args.ShowBytes)) == ERROR_SUCCESS
  173. && (error = WriteTraceSettingsDwordKey(SHOWAPITRACE_VARIABLE_NAME, Args.ShowApiTrace) ) == ERROR_SUCCESS
  174. && (error = WriteTraceSettingsDwordKey(MAXFILESIZE_VARIABLE_NAME, Args.MaxFileSize) ) == ERROR_SUCCESS)
  175. {
  176. fprintf(stderr, "Updated trace settings\n");
  177. }
  178. else
  179. {
  180. fprintf(stderr, "Error (%s) writing trace settings.\n", InternetMapError(error));
  181. }
  182. }
  183. void ViewTraceSettings()
  184. {
  185. ARGS Args;
  186. ReadTraceSettingsDwordKey(TRACE_ENABLED_VARIABLE_NAME, &(Args.TracingEnabled));
  187. char lpszFilenamePrefix[MAX_PATH + 1];
  188. DWORD dwDummy = sizeof(lpszFilenamePrefix) - 1;
  189. if(ReadTraceSettingsStringKey(LOG_FILE_PREFIX_VARIABLE_NAME, lpszFilenamePrefix, &dwDummy) == ERROR_SUCCESS)
  190. {
  191. Args.FileNamePrefix = lpszFilenamePrefix;
  192. }
  193. ReadTraceSettingsDwordKey(TO_FILE_OR_DEBUGGER_VARIABLE_NAME, &(Args.ToFileOrDebugger));
  194. ReadTraceSettingsDwordKey(SHOWBYTES_VARIABLE_NAME, &(Args.ShowBytes));
  195. ReadTraceSettingsDwordKey(SHOWAPITRACE_VARIABLE_NAME, &(Args.ShowApiTrace));
  196. ReadTraceSettingsDwordKey(MAXFILESIZE_VARIABLE_NAME, &(Args.MaxFileSize));
  197. ARGS ArgsUntouched;
  198. if (Args == ArgsUntouched)
  199. {
  200. fprintf(stderr, "\nWinHttp trace configuration not set.\n");
  201. return;
  202. }
  203. fprintf(stdout, "\nCurrent WinHTTP trace settings under\n\n HKEY_LOCAL_MACHINE\\\n %s:\n\n", INTERNET_TRACE_SETTINGS_KEY);
  204. DWORD TracingEnabled;
  205. char * FileNamePrefix;
  206. DWORD ToFileOrDebugger;
  207. DWORD ShowBytes;
  208. DWORD ShowApiTrace;
  209. DWORD MaxFileSize;
  210. OUTPUT_MESSAGE(TracingEnabled, Args.TracingEnabled, 0);
  211. OUTPUT_MESSAGE(ToFileOrDebugger, Args.ToFileOrDebugger, 0);
  212. OUTPUT_MESSAGE(ShowBytes, Args.ShowBytes, 1);
  213. OUTPUT_MESSAGE(ShowApiTrace, Args.ShowApiTrace, 0);
  214. OUTPUT_MESSAGE(MaxFileSize, Args.MaxFileSize, MINFILESIZE);
  215. if(Args.FileNamePrefix != NULL)
  216. fprintf(stdout, " FileNamePrefix: %s\n", Args.FileNamePrefix);
  217. else
  218. fprintf(stdout, " FileNamePrefix -key not set- (default value: \"\")\n");
  219. }
  220. int __cdecl main (int argc, char **argv)
  221. {
  222. ARGS Args;
  223. DWORD dwErr;
  224. fprintf (stdout,
  225. "Microsoft (R) WinHTTP Tracing Facility Configuration Tool\n"
  226. "Copyright (C) Microsoft Corporation 2001.\n\n"
  227. );
  228. // Discard program arg.
  229. argv++;
  230. argc--;
  231. ParseArguments(argc, argv, &Args);
  232. if (Args.Error)
  233. {
  234. fprintf (stderr,
  235. "usage:\n"
  236. " WinHttpTraceCfg -? : to view help information\n"
  237. " WinHttpTraceCfg : to view current winhttp trace settings (in HKLM)\n"
  238. " WinHttpTraceCfg [-e <0|1>] [-l [log-file]] [-d <0|1>] [-s <0|1|2>]\n"
  239. " [-t <0|1>] [-m <MaxFileSize>]\n\n"
  240. " -e : 1: enable tracing; 0: disable tracing\n"
  241. " -l : [trace-file-prefix], i.e., \"C:\\Temp\\Test3\"; or simply: \"Test3\"\n"
  242. " -d : 0: output to file; 1: output to debugger; 2: output to both\n"
  243. " -s : 0: show HTTP headers only; 1: ANSI output; 2: Hex output\n"
  244. " -t : 1: enable top-level API traces; 0: disable top-level API traces\n"
  245. " -m : Maximum size the trace file can grow to\n"
  246. "");
  247. }
  248. else
  249. {
  250. if(argc)
  251. SetTraceSettings(Args);
  252. ViewTraceSettings();
  253. }
  254. return 0;
  255. }
  256. LPSTR InternetMapError(DWORD Error)
  257. /*++
  258. Routine Description:
  259. Map error code to string. Try to get all errors that might ever be returned
  260. by an Internet function
  261. Arguments:
  262. Error - code to map
  263. Return Value:
  264. LPSTR - pointer to symbolic error name
  265. --*/
  266. {
  267. switch (Error)
  268. {
  269. //
  270. // WINERROR errors
  271. //
  272. CASE_OF(ERROR_SUCCESS);
  273. CASE_OF(ERROR_INVALID_FUNCTION);
  274. CASE_OF(ERROR_FILE_NOT_FOUND);
  275. CASE_OF(ERROR_PATH_NOT_FOUND);
  276. CASE_OF(ERROR_TOO_MANY_OPEN_FILES);
  277. CASE_OF(ERROR_ACCESS_DENIED);
  278. CASE_OF(ERROR_INVALID_HANDLE);
  279. CASE_OF(ERROR_ARENA_TRASHED);
  280. CASE_OF(ERROR_NOT_ENOUGH_MEMORY);
  281. CASE_OF(ERROR_INVALID_BLOCK);
  282. CASE_OF(ERROR_BAD_ENVIRONMENT);
  283. CASE_OF(ERROR_BAD_FORMAT);
  284. CASE_OF(ERROR_INVALID_ACCESS);
  285. CASE_OF(ERROR_INVALID_DATA);
  286. CASE_OF(ERROR_OUTOFMEMORY);
  287. CASE_OF(ERROR_INVALID_DRIVE);
  288. CASE_OF(ERROR_CURRENT_DIRECTORY);
  289. CASE_OF(ERROR_NOT_SAME_DEVICE);
  290. CASE_OF(ERROR_NO_MORE_FILES);
  291. CASE_OF(ERROR_WRITE_PROTECT);
  292. CASE_OF(ERROR_BAD_UNIT);
  293. CASE_OF(ERROR_NOT_READY);
  294. CASE_OF(ERROR_BAD_COMMAND);
  295. CASE_OF(ERROR_CRC);
  296. CASE_OF(ERROR_BAD_LENGTH);
  297. CASE_OF(ERROR_SEEK);
  298. CASE_OF(ERROR_NOT_DOS_DISK);
  299. CASE_OF(ERROR_SECTOR_NOT_FOUND);
  300. CASE_OF(ERROR_OUT_OF_PAPER);
  301. CASE_OF(ERROR_WRITE_FAULT);
  302. CASE_OF(ERROR_READ_FAULT);
  303. CASE_OF(ERROR_GEN_FAILURE);
  304. CASE_OF(ERROR_SHARING_VIOLATION);
  305. CASE_OF(ERROR_LOCK_VIOLATION);
  306. CASE_OF(ERROR_WRONG_DISK);
  307. CASE_OF(ERROR_SHARING_BUFFER_EXCEEDED);
  308. CASE_OF(ERROR_HANDLE_EOF);
  309. CASE_OF(ERROR_HANDLE_DISK_FULL);
  310. CASE_OF(ERROR_NOT_SUPPORTED);
  311. CASE_OF(ERROR_REM_NOT_LIST);
  312. CASE_OF(ERROR_DUP_NAME);
  313. CASE_OF(ERROR_BAD_NETPATH);
  314. CASE_OF(ERROR_NETWORK_BUSY);
  315. CASE_OF(ERROR_DEV_NOT_EXIST);
  316. CASE_OF(ERROR_TOO_MANY_CMDS);
  317. CASE_OF(ERROR_ADAP_HDW_ERR);
  318. CASE_OF(ERROR_BAD_NET_RESP);
  319. CASE_OF(ERROR_UNEXP_NET_ERR);
  320. CASE_OF(ERROR_BAD_REM_ADAP);
  321. CASE_OF(ERROR_PRINTQ_FULL);
  322. CASE_OF(ERROR_NO_SPOOL_SPACE);
  323. CASE_OF(ERROR_PRINT_CANCELLED);
  324. CASE_OF(ERROR_NETNAME_DELETED);
  325. CASE_OF(ERROR_NETWORK_ACCESS_DENIED);
  326. CASE_OF(ERROR_BAD_DEV_TYPE);
  327. CASE_OF(ERROR_BAD_NET_NAME);
  328. CASE_OF(ERROR_TOO_MANY_NAMES);
  329. CASE_OF(ERROR_TOO_MANY_SESS);
  330. CASE_OF(ERROR_SHARING_PAUSED);
  331. CASE_OF(ERROR_REQ_NOT_ACCEP);
  332. CASE_OF(ERROR_REDIR_PAUSED);
  333. CASE_OF(ERROR_FILE_EXISTS);
  334. CASE_OF(ERROR_CANNOT_MAKE);
  335. CASE_OF(ERROR_FAIL_I24);
  336. CASE_OF(ERROR_OUT_OF_STRUCTURES);
  337. CASE_OF(ERROR_ALREADY_ASSIGNED);
  338. CASE_OF(ERROR_INVALID_PASSWORD);
  339. CASE_OF(ERROR_INVALID_PARAMETER);
  340. CASE_OF(ERROR_NET_WRITE_FAULT);
  341. CASE_OF(ERROR_NO_PROC_SLOTS);
  342. CASE_OF(ERROR_TOO_MANY_SEMAPHORES);
  343. CASE_OF(ERROR_EXCL_SEM_ALREADY_OWNED);
  344. CASE_OF(ERROR_SEM_IS_SET);
  345. CASE_OF(ERROR_TOO_MANY_SEM_REQUESTS);
  346. CASE_OF(ERROR_INVALID_AT_INTERRUPT_TIME);
  347. CASE_OF(ERROR_SEM_OWNER_DIED);
  348. CASE_OF(ERROR_SEM_USER_LIMIT);
  349. CASE_OF(ERROR_DISK_CHANGE);
  350. CASE_OF(ERROR_DRIVE_LOCKED);
  351. CASE_OF(ERROR_BROKEN_PIPE);
  352. CASE_OF(ERROR_OPEN_FAILED);
  353. CASE_OF(ERROR_BUFFER_OVERFLOW);
  354. CASE_OF(ERROR_DISK_FULL);
  355. CASE_OF(ERROR_NO_MORE_SEARCH_HANDLES);
  356. CASE_OF(ERROR_INVALID_TARGET_HANDLE);
  357. CASE_OF(ERROR_INVALID_CATEGORY);
  358. CASE_OF(ERROR_INVALID_VERIFY_SWITCH);
  359. CASE_OF(ERROR_BAD_DRIVER_LEVEL);
  360. CASE_OF(ERROR_CALL_NOT_IMPLEMENTED);
  361. CASE_OF(ERROR_SEM_TIMEOUT);
  362. CASE_OF(ERROR_INSUFFICIENT_BUFFER);
  363. CASE_OF(ERROR_INVALID_NAME);
  364. CASE_OF(ERROR_INVALID_LEVEL);
  365. CASE_OF(ERROR_NO_VOLUME_LABEL);
  366. CASE_OF(ERROR_MOD_NOT_FOUND);
  367. CASE_OF(ERROR_PROC_NOT_FOUND);
  368. CASE_OF(ERROR_WAIT_NO_CHILDREN);
  369. CASE_OF(ERROR_CHILD_NOT_COMPLETE);
  370. CASE_OF(ERROR_DIRECT_ACCESS_HANDLE);
  371. CASE_OF(ERROR_NEGATIVE_SEEK);
  372. CASE_OF(ERROR_SEEK_ON_DEVICE);
  373. CASE_OF(ERROR_DIR_NOT_ROOT);
  374. CASE_OF(ERROR_DIR_NOT_EMPTY);
  375. CASE_OF(ERROR_PATH_BUSY);
  376. CASE_OF(ERROR_SYSTEM_TRACE);
  377. CASE_OF(ERROR_INVALID_EVENT_COUNT);
  378. CASE_OF(ERROR_TOO_MANY_MUXWAITERS);
  379. CASE_OF(ERROR_INVALID_LIST_FORMAT);
  380. CASE_OF(ERROR_BAD_ARGUMENTS);
  381. CASE_OF(ERROR_BAD_PATHNAME);
  382. CASE_OF(ERROR_BUSY);
  383. CASE_OF(ERROR_CANCEL_VIOLATION);
  384. CASE_OF(ERROR_ALREADY_EXISTS);
  385. CASE_OF(ERROR_FILENAME_EXCED_RANGE);
  386. CASE_OF(ERROR_LOCKED);
  387. CASE_OF(ERROR_NESTING_NOT_ALLOWED);
  388. CASE_OF(ERROR_BAD_PIPE);
  389. CASE_OF(ERROR_PIPE_BUSY);
  390. CASE_OF(ERROR_NO_DATA);
  391. CASE_OF(ERROR_PIPE_NOT_CONNECTED);
  392. CASE_OF(ERROR_MORE_DATA);
  393. CASE_OF(ERROR_NO_MORE_ITEMS);
  394. CASE_OF(ERROR_NOT_OWNER);
  395. CASE_OF(ERROR_PARTIAL_COPY);
  396. CASE_OF(ERROR_MR_MID_NOT_FOUND);
  397. CASE_OF(ERROR_INVALID_ADDRESS);
  398. CASE_OF(ERROR_PIPE_CONNECTED);
  399. CASE_OF(ERROR_PIPE_LISTENING);
  400. CASE_OF(ERROR_OPERATION_ABORTED);
  401. CASE_OF(ERROR_IO_INCOMPLETE);
  402. CASE_OF(ERROR_IO_PENDING);
  403. CASE_OF(ERROR_NOACCESS);
  404. CASE_OF(ERROR_STACK_OVERFLOW);
  405. CASE_OF(ERROR_INVALID_FLAGS);
  406. CASE_OF(ERROR_NO_TOKEN);
  407. CASE_OF(ERROR_BADDB);
  408. CASE_OF(ERROR_BADKEY);
  409. CASE_OF(ERROR_CANTOPEN);
  410. CASE_OF(ERROR_CANTREAD);
  411. CASE_OF(ERROR_CANTWRITE);
  412. CASE_OF(ERROR_REGISTRY_RECOVERED);
  413. CASE_OF(ERROR_REGISTRY_CORRUPT);
  414. CASE_OF(ERROR_REGISTRY_IO_FAILED);
  415. CASE_OF(ERROR_NOT_REGISTRY_FILE);
  416. CASE_OF(ERROR_KEY_DELETED);
  417. CASE_OF(ERROR_CIRCULAR_DEPENDENCY);
  418. CASE_OF(ERROR_SERVICE_NOT_ACTIVE);
  419. CASE_OF(ERROR_DLL_INIT_FAILED);
  420. CASE_OF(ERROR_CANCELLED);
  421. CASE_OF(ERROR_BAD_USERNAME);
  422. CASE_OF(ERROR_LOGON_FAILURE);
  423. CASE_OF(WAIT_FAILED);
  424. //CASE_OF(WAIT_ABANDONED_0);
  425. CASE_OF(WAIT_TIMEOUT);
  426. CASE_OF(WAIT_IO_COMPLETION);
  427. //CASE_OF(STILL_ACTIVE);
  428. CASE_OF(RPC_S_INVALID_STRING_BINDING);
  429. CASE_OF(RPC_S_WRONG_KIND_OF_BINDING);
  430. CASE_OF(RPC_S_INVALID_BINDING);
  431. CASE_OF(RPC_S_PROTSEQ_NOT_SUPPORTED);
  432. CASE_OF(RPC_S_INVALID_RPC_PROTSEQ);
  433. CASE_OF(RPC_S_INVALID_STRING_UUID);
  434. CASE_OF(RPC_S_INVALID_ENDPOINT_FORMAT);
  435. CASE_OF(RPC_S_INVALID_NET_ADDR);
  436. CASE_OF(RPC_S_NO_ENDPOINT_FOUND);
  437. CASE_OF(RPC_S_INVALID_TIMEOUT);
  438. CASE_OF(RPC_S_OBJECT_NOT_FOUND);
  439. CASE_OF(RPC_S_ALREADY_REGISTERED);
  440. CASE_OF(RPC_S_TYPE_ALREADY_REGISTERED);
  441. CASE_OF(RPC_S_ALREADY_LISTENING);
  442. CASE_OF(RPC_S_NO_PROTSEQS_REGISTERED);
  443. CASE_OF(RPC_S_NOT_LISTENING);
  444. CASE_OF(RPC_S_UNKNOWN_MGR_TYPE);
  445. CASE_OF(RPC_S_UNKNOWN_IF);
  446. CASE_OF(RPC_S_NO_BINDINGS);
  447. CASE_OF(RPC_S_NO_PROTSEQS);
  448. CASE_OF(RPC_S_CANT_CREATE_ENDPOINT);
  449. CASE_OF(RPC_S_OUT_OF_RESOURCES);
  450. CASE_OF(RPC_S_SERVER_UNAVAILABLE);
  451. CASE_OF(RPC_S_SERVER_TOO_BUSY);
  452. CASE_OF(RPC_S_INVALID_NETWORK_OPTIONS);
  453. CASE_OF(RPC_S_NO_CALL_ACTIVE);
  454. CASE_OF(RPC_S_CALL_FAILED);
  455. CASE_OF(RPC_S_CALL_FAILED_DNE);
  456. CASE_OF(RPC_S_PROTOCOL_ERROR);
  457. CASE_OF(RPC_S_UNSUPPORTED_TRANS_SYN);
  458. CASE_OF(RPC_S_UNSUPPORTED_TYPE);
  459. CASE_OF(RPC_S_INVALID_TAG);
  460. CASE_OF(RPC_S_INVALID_BOUND);
  461. CASE_OF(RPC_S_NO_ENTRY_NAME);
  462. CASE_OF(RPC_S_INVALID_NAME_SYNTAX);
  463. CASE_OF(RPC_S_UNSUPPORTED_NAME_SYNTAX);
  464. CASE_OF(RPC_S_UUID_NO_ADDRESS);
  465. CASE_OF(RPC_S_DUPLICATE_ENDPOINT);
  466. CASE_OF(RPC_S_UNKNOWN_AUTHN_TYPE);
  467. CASE_OF(RPC_S_MAX_CALLS_TOO_SMALL);
  468. CASE_OF(RPC_S_STRING_TOO_LONG);
  469. CASE_OF(RPC_S_PROTSEQ_NOT_FOUND);
  470. CASE_OF(RPC_S_PROCNUM_OUT_OF_RANGE);
  471. CASE_OF(RPC_S_BINDING_HAS_NO_AUTH);
  472. CASE_OF(RPC_S_UNKNOWN_AUTHN_SERVICE);
  473. CASE_OF(RPC_S_UNKNOWN_AUTHN_LEVEL);
  474. CASE_OF(RPC_S_INVALID_AUTH_IDENTITY);
  475. CASE_OF(RPC_S_UNKNOWN_AUTHZ_SERVICE);
  476. CASE_OF(EPT_S_INVALID_ENTRY);
  477. CASE_OF(EPT_S_CANT_PERFORM_OP);
  478. CASE_OF(EPT_S_NOT_REGISTERED);
  479. CASE_OF(RPC_S_NOTHING_TO_EXPORT);
  480. CASE_OF(RPC_S_INCOMPLETE_NAME);
  481. CASE_OF(RPC_S_INVALID_VERS_OPTION);
  482. CASE_OF(RPC_S_NO_MORE_MEMBERS);
  483. CASE_OF(RPC_S_NOT_ALL_OBJS_UNEXPORTED);
  484. CASE_OF(RPC_S_INTERFACE_NOT_FOUND);
  485. CASE_OF(RPC_S_ENTRY_ALREADY_EXISTS);
  486. CASE_OF(RPC_S_ENTRY_NOT_FOUND);
  487. CASE_OF(RPC_S_NAME_SERVICE_UNAVAILABLE);
  488. CASE_OF(RPC_S_INVALID_NAF_ID);
  489. CASE_OF(RPC_S_CANNOT_SUPPORT);
  490. CASE_OF(RPC_S_NO_CONTEXT_AVAILABLE);
  491. CASE_OF(RPC_S_INTERNAL_ERROR);
  492. CASE_OF(RPC_S_ZERO_DIVIDE);
  493. CASE_OF(RPC_S_ADDRESS_ERROR);
  494. CASE_OF(RPC_S_FP_DIV_ZERO);
  495. CASE_OF(RPC_S_FP_UNDERFLOW);
  496. CASE_OF(RPC_S_FP_OVERFLOW);
  497. CASE_OF(RPC_X_NO_MORE_ENTRIES);
  498. CASE_OF(RPC_X_SS_CHAR_TRANS_OPEN_FAIL);
  499. CASE_OF(RPC_X_SS_CHAR_TRANS_SHORT_FILE);
  500. CASE_OF(RPC_X_SS_IN_NULL_CONTEXT);
  501. CASE_OF(RPC_X_SS_CONTEXT_DAMAGED);
  502. CASE_OF(RPC_X_SS_HANDLES_MISMATCH);
  503. CASE_OF(RPC_X_SS_CANNOT_GET_CALL_HANDLE);
  504. CASE_OF(RPC_X_NULL_REF_POINTER);
  505. CASE_OF(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
  506. CASE_OF(RPC_X_BYTE_COUNT_TOO_SMALL);
  507. CASE_OF(RPC_X_BAD_STUB_DATA);
  508. //
  509. // WININET errors
  510. //
  511. CASE_OF(ERROR_INTERNET_OUT_OF_HANDLES);
  512. CASE_OF(ERROR_INTERNET_TIMEOUT);
  513. CASE_OF(ERROR_INTERNET_EXTENDED_ERROR);
  514. CASE_OF(ERROR_INTERNET_INTERNAL_ERROR);
  515. CASE_OF(ERROR_INTERNET_INVALID_URL);
  516. CASE_OF(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
  517. CASE_OF(ERROR_INTERNET_NAME_NOT_RESOLVED);
  518. CASE_OF(ERROR_INTERNET_PROTOCOL_NOT_FOUND);
  519. CASE_OF(ERROR_INTERNET_INVALID_OPTION);
  520. CASE_OF(ERROR_INTERNET_BAD_OPTION_LENGTH);
  521. CASE_OF(ERROR_INTERNET_OPTION_NOT_SETTABLE);
  522. CASE_OF(ERROR_INTERNET_SHUTDOWN);
  523. CASE_OF(ERROR_INTERNET_INCORRECT_USER_NAME);
  524. CASE_OF(ERROR_INTERNET_INCORRECT_PASSWORD);
  525. CASE_OF(ERROR_INTERNET_LOGIN_FAILURE);
  526. CASE_OF(ERROR_INTERNET_INVALID_OPERATION);
  527. CASE_OF(ERROR_INTERNET_OPERATION_CANCELLED);
  528. CASE_OF(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
  529. CASE_OF(ERROR_INTERNET_INCORRECT_HANDLE_STATE);
  530. CASE_OF(ERROR_INTERNET_NOT_PROXY_REQUEST);
  531. CASE_OF(ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND);
  532. CASE_OF(ERROR_INTERNET_BAD_REGISTRY_PARAMETER);
  533. CASE_OF(ERROR_INTERNET_NO_DIRECT_ACCESS);
  534. CASE_OF(ERROR_INTERNET_NO_CONTEXT);
  535. CASE_OF(ERROR_INTERNET_NO_CALLBACK);
  536. CASE_OF(ERROR_INTERNET_REQUEST_PENDING);
  537. CASE_OF(ERROR_INTERNET_INCORRECT_FORMAT);
  538. CASE_OF(ERROR_INTERNET_ITEM_NOT_FOUND);
  539. CASE_OF(ERROR_INTERNET_CANNOT_CONNECT);
  540. CASE_OF(ERROR_INTERNET_CONNECTION_ABORTED);
  541. CASE_OF(ERROR_INTERNET_CONNECTION_RESET);
  542. CASE_OF(ERROR_INTERNET_FORCE_RETRY);
  543. CASE_OF(ERROR_INTERNET_INVALID_PROXY_REQUEST);
  544. CASE_OF(ERROR_INTERNET_NEED_UI);
  545. CASE_OF(ERROR_INTERNET_HANDLE_EXISTS);
  546. CASE_OF(ERROR_INTERNET_SEC_CERT_DATE_INVALID);
  547. CASE_OF(ERROR_INTERNET_SEC_CERT_CN_INVALID);
  548. CASE_OF(ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR);
  549. CASE_OF(ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR);
  550. CASE_OF(ERROR_INTERNET_MIXED_SECURITY);
  551. CASE_OF(ERROR_INTERNET_CHG_POST_IS_NON_SECURE);
  552. CASE_OF(ERROR_INTERNET_POST_IS_NON_SECURE);
  553. CASE_OF(ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED);
  554. CASE_OF(ERROR_INTERNET_INVALID_CA);
  555. CASE_OF(ERROR_INTERNET_CLIENT_AUTH_NOT_SETUP);
  556. CASE_OF(ERROR_INTERNET_ASYNC_THREAD_FAILED);
  557. CASE_OF(ERROR_INTERNET_REDIRECT_SCHEME_CHANGE);
  558. CASE_OF(ERROR_INTERNET_DIALOG_PENDING);
  559. CASE_OF(ERROR_INTERNET_RETRY_DIALOG);
  560. CASE_OF(ERROR_INTERNET_HTTPS_HTTP_SUBMIT_REDIR);
  561. CASE_OF(ERROR_INTERNET_INSERT_CDROM);
  562. CASE_OF(ERROR_INTERNET_FORTEZZA_LOGIN_NEEDED);
  563. CASE_OF(ERROR_INTERNET_SEC_CERT_ERRORS);
  564. CASE_OF(ERROR_INTERNET_SECURITY_CHANNEL_ERROR);
  565. CASE_OF(ERROR_INTERNET_UNABLE_TO_CACHE_FILE);
  566. CASE_OF(ERROR_INTERNET_TCPIP_NOT_INSTALLED);
  567. CASE_OF(ERROR_INTERNET_SERVER_UNREACHABLE);
  568. CASE_OF(ERROR_INTERNET_PROXY_SERVER_UNREACHABLE);
  569. CASE_OF(ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT);
  570. CASE_OF(ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT);
  571. CASE_OF(ERROR_INTERNET_SEC_INVALID_CERT);
  572. CASE_OF(ERROR_INTERNET_SEC_CERT_REVOKED);
  573. CASE_OF(ERROR_INTERNET_FAILED_DUETOSECURITYCHECK);
  574. CASE_OF(ERROR_INTERNET_NOT_INITIALIZED);
  575. CASE_OF(ERROR_HTTP_HEADER_NOT_FOUND);
  576. CASE_OF(ERROR_HTTP_DOWNLEVEL_SERVER);
  577. CASE_OF(ERROR_HTTP_INVALID_SERVER_RESPONSE);
  578. CASE_OF(ERROR_HTTP_INVALID_HEADER);
  579. CASE_OF(ERROR_HTTP_INVALID_QUERY_REQUEST);
  580. CASE_OF(ERROR_HTTP_HEADER_ALREADY_EXISTS);
  581. CASE_OF(ERROR_HTTP_REDIRECT_FAILED);
  582. CASE_OF(ERROR_HTTP_NOT_REDIRECTED);
  583. CASE_OF(ERROR_HTTP_COOKIE_NEEDS_CONFIRMATION);
  584. CASE_OF(ERROR_HTTP_COOKIE_DECLINED);
  585. CASE_OF(ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION);
  586. //
  587. // SSPI errors
  588. //
  589. CASE_OF(SEC_E_INSUFFICIENT_MEMORY);
  590. CASE_OF(SEC_E_INVALID_HANDLE);
  591. CASE_OF(SEC_E_UNSUPPORTED_FUNCTION);
  592. CASE_OF(SEC_E_TARGET_UNKNOWN);
  593. CASE_OF(SEC_E_INTERNAL_ERROR);
  594. CASE_OF(SEC_E_SECPKG_NOT_FOUND);
  595. CASE_OF(SEC_E_NOT_OWNER);
  596. CASE_OF(SEC_E_CANNOT_INSTALL);
  597. CASE_OF(SEC_E_INVALID_TOKEN);
  598. CASE_OF(SEC_E_CANNOT_PACK);
  599. CASE_OF(SEC_E_QOP_NOT_SUPPORTED);
  600. CASE_OF(SEC_E_NO_IMPERSONATION);
  601. CASE_OF(SEC_E_LOGON_DENIED);
  602. CASE_OF(SEC_E_UNKNOWN_CREDENTIALS);
  603. CASE_OF(SEC_E_NO_CREDENTIALS);
  604. CASE_OF(SEC_E_MESSAGE_ALTERED);
  605. CASE_OF(SEC_E_OUT_OF_SEQUENCE);
  606. CASE_OF(SEC_E_NO_AUTHENTICATING_AUTHORITY);
  607. CASE_OF(SEC_I_CONTINUE_NEEDED);
  608. CASE_OF(SEC_I_COMPLETE_NEEDED);
  609. CASE_OF(SEC_I_COMPLETE_AND_CONTINUE);
  610. CASE_OF(SEC_I_LOCAL_LOGON);
  611. CASE_OF(SEC_E_BAD_PKGID);
  612. CASE_OF(SEC_E_CONTEXT_EXPIRED);
  613. CASE_OF(SEC_E_INCOMPLETE_MESSAGE);
  614. //
  615. // WINSOCK errors
  616. //
  617. CASE_OF(WSAEINTR);
  618. CASE_OF(WSAEBADF);
  619. CASE_OF(WSAEACCES);
  620. CASE_OF(WSAEFAULT);
  621. CASE_OF(WSAEINVAL);
  622. CASE_OF(WSAEMFILE);
  623. CASE_OF(WSAEWOULDBLOCK);
  624. CASE_OF(WSAEINPROGRESS);
  625. CASE_OF(WSAEALREADY);
  626. CASE_OF(WSAENOTSOCK);
  627. CASE_OF(WSAEDESTADDRREQ);
  628. CASE_OF(WSAEMSGSIZE);
  629. CASE_OF(WSAEPROTOTYPE);
  630. CASE_OF(WSAENOPROTOOPT);
  631. CASE_OF(WSAEPROTONOSUPPORT);
  632. CASE_OF(WSAESOCKTNOSUPPORT);
  633. CASE_OF(WSAEOPNOTSUPP);
  634. CASE_OF(WSAEPFNOSUPPORT);
  635. CASE_OF(WSAEAFNOSUPPORT);
  636. CASE_OF(WSAEADDRINUSE);
  637. CASE_OF(WSAEADDRNOTAVAIL);
  638. CASE_OF(WSAENETDOWN);
  639. CASE_OF(WSAENETUNREACH);
  640. CASE_OF(WSAENETRESET);
  641. CASE_OF(WSAECONNABORTED);
  642. CASE_OF(WSAECONNRESET);
  643. CASE_OF(WSAENOBUFS);
  644. CASE_OF(WSAEISCONN);
  645. CASE_OF(WSAENOTCONN);
  646. CASE_OF(WSAESHUTDOWN);
  647. CASE_OF(WSAETOOMANYREFS);
  648. CASE_OF(WSAETIMEDOUT);
  649. CASE_OF(WSAECONNREFUSED);
  650. CASE_OF(WSAELOOP);
  651. CASE_OF(WSAENAMETOOLONG);
  652. CASE_OF(WSAEHOSTDOWN);
  653. CASE_OF(WSAEHOSTUNREACH);
  654. CASE_OF(WSAENOTEMPTY);
  655. CASE_OF(WSAEPROCLIM);
  656. CASE_OF(WSAEUSERS);
  657. CASE_OF(WSAEDQUOT);
  658. CASE_OF(WSAESTALE);
  659. CASE_OF(WSAEREMOTE);
  660. CASE_OF(WSAEDISCON);
  661. CASE_OF(WSASYSNOTREADY);
  662. CASE_OF(WSAVERNOTSUPPORTED);
  663. CASE_OF(WSANOTINITIALISED);
  664. CASE_OF(WSAHOST_NOT_FOUND);
  665. CASE_OF(WSATRY_AGAIN);
  666. CASE_OF(WSANO_RECOVERY);
  667. CASE_OF(WSANO_DATA);
  668. default:
  669. return "?";
  670. }
  671. }
  672. //
  673. // private functions based on registry.cxx and notifctn.cxx:
  674. //
  675. DWORD
  676. ReadRegistryDword(
  677. IN HKEY Key,
  678. IN LPCSTR ParameterName,
  679. OUT LPDWORD ParameterValue
  680. )
  681. {
  682. DWORD error;
  683. DWORD valueLength;
  684. DWORD valueType;
  685. DWORD value;
  686. valueLength = sizeof(*ParameterValue);
  687. error = (DWORD)RegQueryValueEx(Key,
  688. ParameterName,
  689. NULL, // reserved
  690. &valueType,
  691. (LPBYTE)&value,
  692. &valueLength
  693. );
  694. //
  695. // if the size or type aren't correct then return an error, else only if
  696. // success was returned do we modify *ParameterValue
  697. //
  698. if (error == ERROR_SUCCESS) {
  699. if (((valueType != REG_DWORD)
  700. && (valueType != REG_BINARY))
  701. || (valueLength != sizeof(DWORD))) {
  702. error = ERROR_PATH_NOT_FOUND;
  703. } else {
  704. *ParameterValue = value;
  705. }
  706. }
  707. return error;
  708. }
  709. DWORD
  710. ReadTraceSettingsDwordKey(
  711. IN LPCSTR ParameterName,
  712. OUT LPDWORD ParameterValue
  713. )
  714. {
  715. HKEY ParameterKey = BASE_TRACE_KEY;
  716. LPCSTR keyToReadFrom = INTERNET_TRACE_SETTINGS_KEY;
  717. HKEY clientKey;
  718. DWORD error = ERROR_SUCCESS;
  719. error = REGOPENKEYEX(ParameterKey,
  720. keyToReadFrom,
  721. 0, // reserved
  722. KEY_QUERY_VALUE,
  723. &clientKey
  724. );
  725. if (error == ERROR_SUCCESS) {
  726. error = ReadRegistryDword(clientKey,
  727. ParameterName,
  728. ParameterValue
  729. );
  730. REGCLOSEKEY(clientKey);
  731. }
  732. return error;
  733. }
  734. DWORD
  735. ReadRegistryOemString(
  736. IN HKEY Key,
  737. IN LPCSTR ParameterName,
  738. OUT LPSTR String,
  739. IN OUT LPDWORD Length
  740. )
  741. {
  742. LONG error;
  743. DWORD valueType;
  744. LPSTR str;
  745. DWORD valueLength;
  746. //
  747. // first, get the length of the string
  748. //
  749. valueLength = *Length;
  750. error = RegQueryValueEx(Key,
  751. ParameterName,
  752. NULL, // reserved
  753. &valueType,
  754. (LPBYTE)String,
  755. &valueLength
  756. );
  757. if (error != ERROR_SUCCESS) {
  758. goto quit;
  759. }
  760. //
  761. // we only support REG_SZ (single string) values in this function
  762. //
  763. if (valueType != REG_SZ) {
  764. error = ERROR_PATH_NOT_FOUND;
  765. goto quit;
  766. }
  767. //
  768. // if 1 or 0 chars returned then the string is empty
  769. //
  770. if (valueLength <= sizeof(char)) {
  771. error = ERROR_PATH_NOT_FOUND;
  772. goto quit;
  773. }
  774. //
  775. // convert the ANSI string to OEM character set in place. According to Win
  776. // help, this always succeeds
  777. //
  778. CharToOem(String, String);
  779. //
  780. // return the length as if returned from strlen() (i.e. drop the '\0')
  781. //
  782. *Length = valueLength - sizeof(char);
  783. quit:
  784. return error;
  785. }
  786. DWORD
  787. ReadTraceSettingsStringKey(
  788. IN LPCSTR ParameterName,
  789. OUT LPSTR ParameterValue,
  790. IN OUT LPDWORD ParameterLength
  791. )
  792. {
  793. HKEY ParameterKey = BASE_TRACE_KEY;
  794. LPCSTR keyToReadFrom = INTERNET_TRACE_SETTINGS_KEY;
  795. HKEY clientKey;
  796. //
  797. // zero-terminate the string
  798. //
  799. if (*ParameterLength > 0) {
  800. *ParameterValue = '\0';
  801. }
  802. DWORD error = ERROR_SUCCESS;
  803. error = REGOPENKEYEX(ParameterKey,
  804. keyToReadFrom,
  805. 0, // reserved
  806. KEY_QUERY_VALUE,
  807. &clientKey
  808. );
  809. if (error == ERROR_SUCCESS) {
  810. error = ReadRegistryOemString(clientKey,
  811. ParameterName,
  812. ParameterValue,
  813. ParameterLength
  814. );
  815. REGCLOSEKEY(clientKey);
  816. }
  817. return error;
  818. }
  819. DWORD
  820. WriteTraceSettingsDwordKey(
  821. IN LPCSTR ParameterName,
  822. IN DWORD ParameterValue
  823. )
  824. {
  825. DWORD error;
  826. DWORD valueLength;
  827. DWORD valueType;
  828. DWORD value;
  829. if(ParameterValue == INVALID_VALUE)
  830. return ERROR_SUCCESS;
  831. LPCSTR keyToReadFrom = INTERNET_TRACE_SETTINGS_KEY;
  832. HKEY hKey = NULL;
  833. DWORD dwDisposition;
  834. if ((error = REGCREATEKEYEX(BASE_TRACE_KEY, keyToReadFrom, 0, NULL, 0, KEY_SET_VALUE,NULL, &hKey,&dwDisposition)) == ERROR_SUCCESS)
  835. {
  836. valueLength = sizeof(ParameterValue);
  837. valueType = REG_DWORD;
  838. value = ParameterValue;
  839. error = (DWORD)RegSetValueEx(hKey,
  840. ParameterName,
  841. NULL, // reserved
  842. valueType,
  843. (LPBYTE)&value,
  844. valueLength
  845. );
  846. REGCLOSEKEY(hKey);
  847. }
  848. return error;
  849. }
  850. DWORD WriteTraceSettingsStringKey(
  851. IN LPCSTR pszKey,
  852. IN LPSTR pszValue,
  853. IN DWORD dwSize)
  854. {
  855. LPCSTR keyToReadFrom = INTERNET_TRACE_SETTINGS_KEY;
  856. DWORD dwError;
  857. DWORD dwDisposition;
  858. if(pszValue == NULL)
  859. return ERROR_SUCCESS;
  860. HKEY hKey = NULL;
  861. char szValue[SZREGVALUE_MAX];
  862. DWORD dwValueLen = SZREGVALUE_MAX;
  863. if ((dwError = RegCreateKeyEx(BASE_TRACE_KEY, keyToReadFrom, 0, NULL, 0, KEY_SET_VALUE,NULL, &hKey,&dwDisposition)) == ERROR_SUCCESS)
  864. {
  865. dwError = RegSetValueEx(hKey, pszKey, NULL, REG_SZ,(const BYTE *)pszValue, dwSize);
  866. REGCLOSEKEY(hKey);
  867. }
  868. return dwError;
  869. }