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.

358 lines
10 KiB

  1. /*
  2. Main.c
  3. Tests the dialup server ui.
  4. Paul Mayfield, 9/30/97
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <windows.h>
  9. #include <rasuip.h>
  10. #include <rassrvp.h>
  11. #define mbtowc(wname, aname) MultiByteToWideChar(CP_ACP,0,aname,-1,wname,1024)
  12. BOOL TempFunc(int argc, char ** argv);
  13. // Error reporting
  14. void PrintErr(DWORD err) {
  15. WCHAR buf[1024];
  16. FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,NULL,err,(DWORD)NULL,buf,1024,NULL);
  17. wprintf(buf);
  18. wprintf(L"\n");
  19. }
  20. // Function adds pages to a property sheet
  21. BOOL CALLBACK AddPageProc(HPROPSHEETPAGE hPage, LPARAM lParam) {
  22. PROPSHEETHEADER * pHeader = (PROPSHEETHEADER*)lParam;
  23. HPROPSHEETPAGE * phpage = pHeader->phpage;
  24. DWORD i;
  25. // Increment
  26. pHeader->nPages++;
  27. // Resize
  28. pHeader->phpage = (HPROPSHEETPAGE *) malloc(sizeof(HPROPSHEETPAGE) * pHeader->nPages);
  29. if (!pHeader->phpage)
  30. return FALSE;
  31. // Copy
  32. for (i = 0; i < pHeader->nPages - 1; i++)
  33. pHeader->phpage[i] = phpage[i];
  34. pHeader->phpage[i] = hPage;
  35. // Free
  36. if (phpage)
  37. free(phpage);
  38. return TRUE;
  39. }
  40. // Displays the properties ui of the dialup server
  41. DWORD DisplayUI() {
  42. PROPSHEETHEADER header;
  43. DWORD dwErr;
  44. /*
  45. ZeroMemory(&header, sizeof(header));
  46. header.dwSize = sizeof(PROPSHEETHEADER);
  47. header.dwFlags = PSH_NOAPPLYNOW | PSH_USECALLBACK;
  48. header.hwndParent = GetFocus();
  49. header.hInstance = GetModuleHandle(NULL);
  50. header.pszCaption = "Incoming Connections";
  51. header.nPages = 0;
  52. header.ppsp = NULL;
  53. // Add the property pages and display
  54. if ((dwErr = RasSrvAddPropPages(NULL, AddPageProc, (LPARAM)&header)) == NO_ERROR) {
  55. int iErr;
  56. iErr = PropertySheet(&header);
  57. if (iErr == -1)
  58. PrintErr(GetLastError());
  59. }
  60. */
  61. return NO_ERROR;
  62. }
  63. DWORD DisplayWizard() {
  64. PROPSHEETHEADER header;
  65. DWORD dwErr;
  66. int iErr;
  67. /*
  68. // Initialize the header
  69. ZeroMemory(&header, sizeof(header));
  70. header.dwSize = sizeof(PROPSHEETHEADER);
  71. header.dwFlags = PSH_NOAPPLYNOW | PSH_USECALLBACK | PSH_WIZARD97;
  72. header.hwndParent = GetFocus();
  73. header.hInstance = GetModuleHandle(NULL);
  74. header.pszCaption = "Incoming Connections";
  75. header.nPages = 0;
  76. header.ppsp = NULL;
  77. // Add the wizard pages
  78. if ((dwErr = RasSrvAddWizPages(AddPageProc, (LPARAM)&header)) != NO_ERROR)
  79. return dwErr;
  80. // Display the property sheet
  81. iErr = PropertySheet(&header);
  82. if (iErr == -1)
  83. PrintErr(GetLastError());
  84. */
  85. return NO_ERROR;
  86. }
  87. DWORD DisplayDccWizard() {
  88. /*
  89. PROPSHEETHEADER header;
  90. DWORD dwErr;
  91. int iErr;
  92. // Initialize the header
  93. ZeroMemory(&header, sizeof(header));
  94. header.dwSize = sizeof(PROPSHEETHEADER);
  95. header.dwFlags = PSH_NOAPPLYNOW | PSH_USECALLBACK | PSH_WIZARD97;
  96. header.hwndParent = GetFocus();
  97. header.hInstance = GetModuleHandle(NULL);
  98. header.pszCaption = "Incoming Connections";
  99. header.nPages = 0;
  100. header.ppsp = NULL;
  101. // Add the wizard pages
  102. if ((dwErr = RassrvAddDccWizPages(AddPageProc, (LPARAM)&header)) != NO_ERROR)
  103. return dwErr;
  104. // Display the property sheet
  105. iErr = PropertySheet(&header);
  106. if (iErr == -1)
  107. PrintErr(GetLastError());
  108. return NO_ERROR;
  109. */
  110. RasUserPrefsDlg ( NULL );
  111. return NO_ERROR;
  112. }
  113. // Enumerates the active connections
  114. void EnumConnections () {
  115. RASSRVCONN pConnList[3];
  116. DWORD dwTot = 3, dwSize = dwTot * sizeof (RASSRVCONN), i, dwErr;
  117. if ((dwErr = RasSrvEnumConnections((LPVOID)&pConnList, &dwSize, &dwTot)) != NO_ERROR)
  118. PrintErr(dwErr);
  119. else {
  120. for (i=0; i < dwTot; i++)
  121. wprintf(L"Connection: %s\n", pConnList[i].szEntryName);
  122. }
  123. }
  124. // Finds the given connection structure in a list. pConn will point to the
  125. // appropriate structure on success, otherwise it will point to NULL. If an
  126. // error occurs, DWORD will contain an error code, otherwise NO_ERROR.
  127. DWORD FindConnectionInList(LPRASSRVCONN lprassrvconn, DWORD dwEntries, PWCHAR pszConnName, LPRASSRVCONN * pConn) {
  128. DWORD i;
  129. if (!pConn || !lprassrvconn)
  130. return ERROR_INVALID_PARAMETER;
  131. for (i = 0; i < dwEntries; i++) {
  132. if (wcscmp(lprassrvconn[i].szEntryName, pszConnName) == 0) {
  133. *pConn = &(lprassrvconn[i]);
  134. break;
  135. }
  136. }
  137. return NO_ERROR;
  138. }
  139. DWORD HangupConnection(char * pszAConnectionName) {
  140. WCHAR pszConnectionName[1024];
  141. RASSRVCONN pConnList[20], *pConn;
  142. DWORD dwTot = 20, dwSize = dwTot * sizeof (RASSRVCONN), i, dwErr;
  143. mbtowc(pszConnectionName, pszAConnectionName);
  144. if ((dwErr = RasSrvEnumConnections((LPVOID)&pConnList, &dwSize, &dwTot)) != NO_ERROR)
  145. return dwErr;
  146. if ((dwErr = FindConnectionInList(pConnList, dwTot, pszConnectionName, &pConn)) != NO_ERROR)
  147. return dwErr;
  148. return RasSrvHangupConnection(pConn->hRasSrvConn);
  149. }
  150. // Displays status of the given active connection
  151. DWORD StatusUI(char * pszAConnectionName) {
  152. printf("Multilink status will not be included in connections.\n");
  153. return NO_ERROR;
  154. }
  155. /*
  156. #define numPages 1
  157. PROPSHEETHEADER header;
  158. PROPSHEETPAGE pPages[numPages];
  159. WCHAR pszConnectionName[1024];
  160. RASSRVCONN pConnList[20], *pConn;
  161. DWORD dwTot = 20, dwSize = dwTot * sizeof (RASSRVCONN), i, dwErr;
  162. mbtowc(pszConnectionName, pszAConnectionName);
  163. if ((dwErr = RasSrvEnumConnections((LPVOID)&pConnList, &dwSize, &dwTot)) != NO_ERROR)
  164. return dwErr;
  165. if ((dwErr = FindConnectionInList(pConnList, dwTot, pszConnectionName, &pConn)) != NO_ERROR)
  166. return dwErr;
  167. if (pConn) {
  168. // Get the property sheet page of the user
  169. dwErr = RasSrvAddPropPage(&(pPages[0]), RASSRVUI_MULTILINK_TAB, (DWORD)pConn->hRasSrvConn);
  170. if (dwErr != NO_ERROR)
  171. return dwErr;
  172. ZeroMemory(&header, sizeof(header));
  173. header.dwSize = sizeof(PROPSHEETHEADER);
  174. header.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW | PSH_USECALLBACK;
  175. header.hwndParent = GetFocus();
  176. header.hInstance = GetModuleHandle(NULL);
  177. header.pszCaption = "Multilink Statistics";
  178. header.nPages = numPages;
  179. header.ppsp = pPages;
  180. // Display the property sheet
  181. PropertySheet(&header);
  182. }
  183. else {
  184. wprintf(L"Unable to find connection: %s\n", pszConnectionName);
  185. return ERROR_CAN_NOT_COMPLETE;
  186. }
  187. return NO_ERROR;
  188. #undef numPages
  189. }
  190. */
  191. DWORD DeleteIcon() {
  192. DWORD dwErr;
  193. printf("Stopping remote access service... ");
  194. dwErr = RasSrvCleanupService();
  195. if (dwErr == NO_ERROR)
  196. printf("Success.\n");
  197. else
  198. printf("\n");
  199. return dwErr;
  200. }
  201. char * GetParam(char * buf) {
  202. char * ptr = strstr(buf, " ");
  203. ptr++;
  204. return ptr;
  205. }
  206. DWORD RunScript(char * filename) {
  207. FILE * f;
  208. char buf[256];
  209. DWORD dwErr;
  210. f = fopen(filename, "r");
  211. if (!f)
  212. return ERROR_OPEN_FAILED;
  213. while (fgets(buf, 256, f)) {
  214. if (buf[strlen(buf)-1] == '\n')
  215. buf[strlen(buf)-1] = 0;
  216. if (strncmp(buf, "-e", 2) == 0)
  217. EnumConnections();
  218. else if (strncmp(buf, "-p", 2) == 0) {
  219. if ((dwErr = DisplayUI()) != NO_ERROR)
  220. PrintErr(dwErr);
  221. }
  222. else if (strncmp(buf, "-s", 2) == 0) {
  223. if ((dwErr = StatusUI(GetParam(buf))) != NO_ERROR)
  224. PrintErr(dwErr);
  225. }
  226. else if (strncmp(buf, "-h", 2) == 0) {
  227. if ((dwErr = HangupConnection(GetParam(buf))) != NO_ERROR)
  228. PrintErr(dwErr);
  229. }
  230. else if (strncmp(buf, "-r", 2) == 0) {
  231. if ((dwErr = RunScript(GetParam(buf))) != NO_ERROR)
  232. PrintErr(dwErr);
  233. }
  234. else if (strncmp(buf, "-w", 2) == 0) {
  235. if ((dwErr = DisplayWizard()) != NO_ERROR)
  236. PrintErr(dwErr);
  237. }
  238. }
  239. fclose(f);
  240. return NO_ERROR;
  241. }
  242. // usage
  243. void usage (char * prog) {
  244. printf("\n");
  245. printf("Usage\n=====\n");
  246. printf("%s -d \t Deletes the incoming connect icon (stop service).\n", prog);
  247. printf("%s -e \t Enumerates the active connections.\n", prog);
  248. printf("%s -h <user> \t Disconnects the given user.\n", prog);
  249. printf("%s -p \t Brings up the dialup server properties page.\n", prog);
  250. printf("%s -r <script>\t Runs the commands in the given script file.\n", prog);
  251. printf("%s -s <user> \t Shows multilink status for the given connected user.\n", prog);
  252. printf("%s -w \t Runs incoming connections wizard.\n", prog);
  253. printf("\n");
  254. printf("Examples\n========\n");
  255. printf("%s -h \"pmay (Paul Mayfield)\" \n", prog);
  256. printf("%s -s \"rosemb (Rose Bigham)\" \n", prog);
  257. printf("%s -r script1.txt\n", prog);
  258. }
  259. void RunTest(int argc, char ** argv) {
  260. DWORD dwErr;
  261. if (argc < 2)
  262. usage(argv[0]);
  263. else {
  264. if (strcmp(argv[1], "-e") == 0)
  265. EnumConnections();
  266. else if (strcmp(argv[1], "-p") == 0) {
  267. if ((dwErr = DisplayUI()) != NO_ERROR)
  268. PrintErr(dwErr);
  269. }
  270. else if (strcmp(argv[1], "-d") == 0) {
  271. if ((dwErr = DeleteIcon()) != NO_ERROR)
  272. PrintErr(dwErr);
  273. }
  274. else if ((argc > 2) && (strcmp(argv[1], "-s") == 0)) {
  275. if ((dwErr = StatusUI(argv[2])) != NO_ERROR)
  276. PrintErr(dwErr);
  277. }
  278. else if ((argc > 2) && (strcmp(argv[1], "-h") == 0)) {
  279. if ((dwErr = HangupConnection(argv[2])) != NO_ERROR)
  280. PrintErr(dwErr);
  281. }
  282. else if ((argc > 2) && (strcmp(argv[1], "-r") == 0)) {
  283. if ((dwErr = RunScript(argv[2])) != NO_ERROR)
  284. PrintErr(dwErr);
  285. }
  286. else if (strcmp(argv[1], "-w") == 0) {
  287. if ((dwErr = DisplayWizard()) != NO_ERROR)
  288. PrintErr(dwErr);
  289. }
  290. else if (strcmp(argv[1], "-c") == 0) {
  291. if ((dwErr = DisplayDccWizard()) != NO_ERROR)
  292. PrintErr(dwErr);
  293. }
  294. else
  295. usage(argv[0]);
  296. }
  297. }
  298. // Main function dispatches all of the work
  299. int _cdecl main (int argc, char ** argv) {
  300. if (! TempFunc(argc, argv))
  301. RunTest(argc, argv);
  302. return 0;
  303. }