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.

207 lines
5.8 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. #include <memory.h>
  5. #include <windows.h>
  6. #include <wininet.h>
  7. #include <wininetd.h>
  8. #ifndef _CRTAPI1
  9. #define _CRTAPI1
  10. #endif
  11. #define IS_ARG(c) (((c) == '-') || ((c) == '/'))
  12. void _CRTAPI1 main(int, char**);
  13. LPVOID get_and_dump_debug_info(LPDWORD);
  14. void dump_internet_debug_info(LPINTERNET_DEBUG_INFO);
  15. void _CRTAPI1 main(int argc, char** argv) {
  16. BOOL ok;
  17. DWORD length;
  18. LPVOID buf;
  19. DWORD inlength;
  20. LPVOID buf2;
  21. HINTERNET hInternet;
  22. HINTERNET hGopher;
  23. char locator[MAX_GOPHER_LOCATOR_LENGTH + 1];
  24. HINTERNET hFind;
  25. GOPHER_FIND_DATA data;
  26. buf = get_and_dump_debug_info(&length);
  27. inlength = length;
  28. length += sizeof("mydebug.log");
  29. buf2 = malloc(length);
  30. if (!buf2) {
  31. printf("error: failed to allocate %d bytes\n", length);
  32. exit(1);
  33. }
  34. memcpy(buf2, buf, inlength);
  35. free(buf);
  36. ((LPINTERNET_DEBUG_INFO)buf2)->CategoryFlags = 0xffffffff;
  37. ((LPINTERNET_DEBUG_INFO)buf2)->ControlFlags = 0x7df;
  38. strcpy(((LPINTERNET_DEBUG_INFO)buf2)->Filename, "mydebug.log");
  39. ok = InternetSetOption(NULL,
  40. INTERNET_OPTION_SET_DEBUG_INFO,
  41. buf2,
  42. length
  43. );
  44. if (!ok) {
  45. printf("error: InternetSetOption() returns %d\n", GetLastError());
  46. exit(1);
  47. }
  48. //
  49. // make sure we set it
  50. //
  51. buf = get_and_dump_debug_info(&length);
  52. free(buf);
  53. //
  54. // try generating some debug info
  55. //
  56. hInternet = InternetOpen("dbginfo",
  57. PRE_CONFIG_INTERNET_ACCESS,
  58. NULL,
  59. 0,
  60. 0
  61. );
  62. if (!hInternet) {
  63. printf("error: InternetOpen() returns %d\n", GetLastError());
  64. exit(1);
  65. }
  66. hGopher = InternetConnect(hInternet,
  67. NULL,
  68. 0,
  69. NULL,
  70. NULL,
  71. INTERNET_SERVICE_GOPHER,
  72. 0,
  73. 0
  74. );
  75. if (!hGopher) {
  76. printf("error: InternetConnect() returns %d\n", GetLastError());
  77. }
  78. length = sizeof(locator);
  79. if (!GopherCreateLocator("rfirthmips",
  80. 0,
  81. NULL,
  82. NULL,
  83. GOPHER_TYPE_DIRECTORY,
  84. locator,
  85. &length
  86. )) {
  87. printf("error: GopherCreateLocator() returns %d\n", GetLastError());
  88. exit(1);
  89. }
  90. hFind = GopherFindFirstFile(hGopher,
  91. locator,
  92. NULL,
  93. &data,
  94. 0
  95. );
  96. if (!hFind) {
  97. printf("error: GopherFindFirstFile() returns %d\n", GetLastError());
  98. }
  99. free(buf2);
  100. exit(0);
  101. }
  102. LPVOID get_and_dump_debug_info(LPDWORD outLen) {
  103. BOOL ok;
  104. DWORD length;
  105. DWORD error;
  106. LPVOID buf;
  107. DWORD inlength;
  108. length = 0;
  109. ok = InternetQueryOption(NULL,
  110. INTERNET_OPTION_GET_DEBUG_INFO,
  111. (LPVOID)0x1234,
  112. &length
  113. );
  114. if (ok) {
  115. printf("error: InternetQueryOption() with zero length returns TRUE\n");
  116. exit(1);
  117. }
  118. error = GetLastError();
  119. if (error != ERROR_INSUFFICIENT_BUFFER) {
  120. printf("error: InternetQueryOption() with zero length returns %d\n", error);
  121. }
  122. printf("InternetQueryOption() with zero length returns %d\n", error);
  123. printf("length = %d\n", length);
  124. length = 65535;
  125. ok = InternetQueryOption(NULL,
  126. INTERNET_OPTION_GET_DEBUG_INFO,
  127. NULL,
  128. &length
  129. );
  130. if (ok) {
  131. printf("error: InternetQueryOption() with no buffer returns %d\n", error);
  132. exit(1);
  133. }
  134. error = GetLastError();
  135. if (error != ERROR_INSUFFICIENT_BUFFER) {
  136. printf("error: InternetQueryOption() with no buffer returns %d\n", error);
  137. }
  138. printf("InternetQueryOption() with no buffer returns %d\n", error);
  139. printf("length = %d\n", length);
  140. buf = malloc(length);
  141. if (!buf) {
  142. printf("error: failed to allocate %d bytes\n", length);
  143. exit(1);
  144. }
  145. inlength = length;
  146. ok = InternetQueryOption(NULL,
  147. INTERNET_OPTION_GET_DEBUG_INFO,
  148. buf,
  149. &length
  150. );
  151. if (!ok) {
  152. printf("error: InternetQueryOption() with %d byte buffer returns %d. Length = %d\n",
  153. inlength,
  154. GetLastError(),
  155. length
  156. );
  157. exit(1);
  158. }
  159. printf("InternetQueryOption() returns %d byte buffer\n", length);
  160. dump_internet_debug_info((LPINTERNET_DEBUG_INFO)buf);
  161. *outLen = length;
  162. return buf;
  163. }
  164. void dump_internet_debug_info(LPINTERNET_DEBUG_INFO info) {
  165. printf("ErrorLevel = %d\n"
  166. "ControlFlags = %x\n"
  167. "CategoryFlags = %x\n"
  168. "BreakFlags = %x\n"
  169. "IndentIncrement = %d\n"
  170. "Filename = \"%s\"\n"
  171. "\n",
  172. info->ErrorLevel,
  173. info->ControlFlags,
  174. info->CategoryFlags,
  175. info->BreakFlags,
  176. info->IndentIncrement,
  177. info->Filename
  178. );
  179. }