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.

297 lines
9.5 KiB

  1. /*++
  2. Copyright (c) 1998, Microsoft Corporation
  3. Module Name:
  4. cstest.c
  5. Abstract:
  6. This module contains code for testing connection-sharing setup.
  7. Author:
  8. Abolade Gbadegesin (aboladeg) 23-Apr-1998
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #include <tchar.h>
  14. #include <winsock.h>
  15. extern
  16. DWORD
  17. SetAdapterIpAddress(
  18. PCHAR AdapterName,
  19. BOOL EnableDhcp,
  20. ULONG IpAddress,
  21. ULONG SubnetMask,
  22. ULONG DefaultGateway
  23. );
  24. #define ArgToSharedConnection(prsc) \
  25. if (argc == 4) { \
  26. RasEntryToSharedConnection((PWCHAR)argv[2],(PWCHAR)argv[3],(prsc)); \
  27. } else if (argc == 3) { \
  28. GUID _Guid; \
  29. UNICODE_STRING _us; \
  30. RtlInitUnicodeString(&_us, (PWCHAR)argv[2]); \
  31. RtlGUIDFromString(&_us, &_Guid); \
  32. RasGuidToSharedConnection(&_Guid,(prsc)); \
  33. }
  34. ULONG
  35. inet_addrw(
  36. PWCHAR Address
  37. )
  38. {
  39. CHAR String[32];
  40. wcstombs(String, Address, sizeof(String));
  41. return inet_addr(String);
  42. }
  43. VOID
  44. DumpSharedAccessSettings(
  45. SAINFO* Info
  46. )
  47. {
  48. SAAPPLICATION* Application;
  49. PLIST_ENTRY Link;
  50. SARESPONSE* Response;
  51. PLIST_ENTRY SavedLink;
  52. SASERVER* Server;
  53. for (Link = Info->ApplicationList.Flink; Link != &Info->ApplicationList;
  54. Link = Link->Flink) {
  55. Application = CONTAINING_RECORD(Link, SAAPPLICATION, Link);
  56. printf("[Application.%08x]\n", Application->Key);
  57. printf("Enabled=%d\n", Application->Enabled);
  58. printf("Title=%ls\n", Application->Title);
  59. printf("Protocol=%d\n", Application->Protocol);
  60. printf("Port=%d\n", ntohs(Application->Port));
  61. printf("ResponseList=");
  62. SavedLink = Link;
  63. Response = NULL;
  64. for (Link = Application->ResponseList.Flink;
  65. Link != &Application->ResponseList; Link = Link->Flink) {
  66. if (Response) { printf(","); }
  67. Response = CONTAINING_RECORD(Link, SARESPONSE, Link);
  68. printf("%d/%d", Response->Protocol, ntohs(Response->StartPort));
  69. if (Response->StartPort != Response->EndPort) {
  70. printf("-%d", ntohs(Response->EndPort));
  71. }
  72. }
  73. Link = SavedLink;
  74. printf("\n\n");
  75. }
  76. for (Link = Info->ServerList.Flink; Link != &Info->ServerList;
  77. Link = Link->Flink) {
  78. Server = CONTAINING_RECORD(Link, SASERVER, Link);
  79. printf("[Server.%08x]\n", Server->Key);
  80. printf("Enabled=%d\n", Server->Enabled);
  81. printf("Title=%ls\n", Server->Title);
  82. printf("Protocol=%d\n", Server->Protocol);
  83. printf("Port=%d\n", ntohs(Server->Port));
  84. printf("InternalName=%ls\n", Server->InternalName);
  85. printf("InternalPort=%d\n", ntohs(Server->InternalPort));
  86. printf(
  87. "ReservedAddress=%s\n",
  88. inet_ntoa(*(PIN_ADDR)&Server->ReservedAddress)
  89. );
  90. printf("\n");
  91. }
  92. }
  93. int __cdecl
  94. wmain(
  95. int argc,
  96. wchar_t* argv[]
  97. )
  98. {
  99. RASSHARECONN rsc;
  100. WSADATA wd;
  101. if (argc < 2) {
  102. printf("cstest 1 - CsQuerySharedPrivateLan\n");
  103. printf("cstest 2 {guid} - CsSetupSharedPrivateLan\n");
  104. printf("cstest 3 - CsStartService\n");
  105. printf("cstest 4 [{pbk,name} | {guid}] - RasIsSharedConnection\n");
  106. printf("cstest 5 - RasQuerySharedConnection\n");
  107. printf("cstest 6 [{pbk,name} | {guid}] - RasShareConnection\n");
  108. printf("cstest 7 - RasUnshareConnection\n");
  109. printf("cstest 8 {guid} {addr} {mask} {gway} - SetAdapterIpAddress\n");
  110. printf("cstest 9 {guid} - SetAdapterIpAddress\n");
  111. printf("cstest 10 {guid} - RasNameFromSharedConnection\n");
  112. printf("cstest 11 {bool} - RasLoadSharedAccessSettings\n");
  113. printf("cstest 12 {guid} - TestBackupAddress\n");
  114. printf("cstest 13 {guid} - TestRestoreAddress\n");
  115. printf("cstest 14 - CsQuerySharedPrivateLanAddress\n");
  116. printf("cstest 15 {guid} - RasSetSharedPrivateLan\n");
  117. return 0;
  118. }
  119. WSAStartup(MAKEWORD(2,2), &wd);
  120. CsDllMain(DLL_PROCESS_ATTACH);
  121. switch (_wtol(argv[1])) {
  122. case 1: {
  123. ULONG Error;
  124. GUID Guid;
  125. NTSTATUS status;
  126. UNICODE_STRING UnicodeString;
  127. Error = CsQuerySharedPrivateLan(&Guid);
  128. status = RtlStringFromGUID(&Guid, &UnicodeString);
  129. printf(
  130. "CsQuerySharedPrivateLan:e=%d,g=%ls\n",
  131. Error,
  132. NT_SUCCESS(status) ? UnicodeString.Buffer : L"{}"
  133. );
  134. if (NT_SUCCESS(status)) { RtlFreeUnicodeString(&UnicodeString); }
  135. break;
  136. }
  137. case 2: {
  138. GUID Guid;
  139. NTSTATUS status;
  140. UNICODE_STRING UnicodeString;
  141. RtlInitUnicodeString(&UnicodeString, (PWCHAR)argv[2]);
  142. status = RtlGUIDFromString(&UnicodeString, &Guid);
  143. if (!NT_SUCCESS(status)) {
  144. printf("RtlGUIDFromString:s=%08x\n", status);
  145. }
  146. else {
  147. printf(
  148. "CsSetupSharedPrivateLan:e=%d\n",
  149. CsSetupSharedPrivateLan(&Guid, TRUE)
  150. );
  151. }
  152. break;
  153. }
  154. case 3: {
  155. printf("CsStartService:e=%d\n", CsStartService());
  156. break;
  157. }
  158. case 4: {
  159. ULONG Error;
  160. BOOL Shared;
  161. ArgToSharedConnection(&rsc);
  162. Error = RasIsSharedConnection(&rsc, &Shared);
  163. printf("RasIsSharedConnection:f=%d,e=%d\n", Shared, Error);
  164. break;
  165. }
  166. case 5: {
  167. ULONG Error;
  168. BOOL Shared;
  169. NTSTATUS status;
  170. UNICODE_STRING UnicodeString;
  171. Error = RasQuerySharedConnection(&rsc);
  172. if (Error) {
  173. printf("RasQuerySharedConnection:e=%d\n", Error);
  174. } else if (rsc.fIsLanConnection) {
  175. status = RtlStringFromGUID(&rsc.guid, &UnicodeString);
  176. printf(
  177. "RasQuerySharedConnection:g=%ls,e=%d\n",
  178. UnicodeString.Buffer, Error
  179. );
  180. RtlFreeUnicodeString(&UnicodeString);
  181. } else {
  182. printf(
  183. "RasQuerySharedConnection:en=%ls,e=%d\n",
  184. rsc.name.szEntryName, Error
  185. );
  186. }
  187. break;
  188. }
  189. case 6: {
  190. ArgToSharedConnection(&rsc);
  191. printf("RasShareConnection:e=%d\n", RasShareConnection(&rsc, NULL));
  192. break;
  193. }
  194. case 7: {
  195. ULONG Error;
  196. BOOL Shared;
  197. Error = RasUnshareConnection(&Shared);
  198. printf("RasUnshareConnection:e=%d,f=%d\n", Error, Shared);
  199. break;
  200. }
  201. case 8: {
  202. ULONG Error;
  203. ULONG Address = inet_addrw(argv[3]);
  204. ULONG Mask = inet_addrw(argv[4]);
  205. ULONG Gateway = inet_addrw(argv[5]);
  206. CHAR String[64];
  207. wcstombs(String, argv[2], sizeof(String));
  208. Error = SetAdapterIpAddress(String, FALSE, Address, Mask, Gateway);
  209. printf("SetAdapterIpAddress=%d\n", Error);
  210. break;
  211. }
  212. case 9: {
  213. ULONG Error;
  214. CHAR String[64];
  215. wcstombs(String, argv[2], sizeof(String));
  216. Error = SetAdapterIpAddress(String, TRUE, 0, 0, 0);
  217. printf("SetAdapterIpAddress=%d\n", Error);
  218. break;
  219. }
  220. case 10: {
  221. ULONG Error;
  222. LPWSTR pszwName;
  223. ArgToSharedConnection(&rsc);
  224. Error = RasNameFromSharedConnection(&rsc, &pszwName);
  225. printf("RasNameFromSharedConnection=%d,n=%ls\n", Error, pszwName);
  226. if (pszwName) { Free(pszwName); }
  227. break;
  228. }
  229. case 11: {
  230. BOOL EnabledOnly = (argc >= 3 ? (BOOL)!!_wtol(argv[2]) : FALSE);
  231. SAINFO* Info = RasLoadSharedAccessSettings(EnabledOnly);
  232. printf("RasLoadSharedAccessSettings=%p\n", Info);
  233. if (Info) {
  234. DumpSharedAccessSettings(Info);
  235. if (argc >= 4) {
  236. RasSaveSharedAccessSettings(Info);
  237. }
  238. RasFreeSharedAccessSettings(Info);
  239. }
  240. break;
  241. }
  242. case 12: {
  243. TestBackupAddress(argv[2]);
  244. break;
  245. }
  246. case 13: {
  247. TestRestoreAddress(argv[2]);
  248. break;
  249. }
  250. case 14: {
  251. ULONG Address = 0;
  252. ULONG Error;
  253. Error = CsQuerySharedPrivateLanAddress(&Address);
  254. printf(
  255. "CsQuerySharedPrivateLanAddress=%s (%d)\n",
  256. inet_ntoa(*(PIN_ADDR)&Address), Error
  257. );
  258. break;
  259. }
  260. case 15: {
  261. GUID Guid;
  262. NTSTATUS status;
  263. UNICODE_STRING UnicodeString;
  264. RtlInitUnicodeString(&UnicodeString, (PWCHAR)argv[2]);
  265. status = RtlGUIDFromString(&UnicodeString, &Guid);
  266. if (!NT_SUCCESS(status)) {
  267. printf("RtlGUIDFromString:s=%08x\n", status);
  268. }
  269. else {
  270. printf(
  271. "RasSetSharedPrivateLan:e=%d\n",
  272. RasSetSharedPrivateLan(&Guid)
  273. );
  274. }
  275. break;
  276. }
  277. }
  278. CsDllMain(DLL_PROCESS_DETACH);
  279. WSACleanup();
  280. return 0;
  281. } // wmain