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.

277 lines
7.6 KiB

  1. /*
  2. File Temp.c
  3. Does temporary stuff.
  4. */
  5. #include "..\\error.h"
  6. #include <stdio.h>
  7. #include <windows.h>
  8. #include <commctrl.h>
  9. #include <lmaccess.h>
  10. #include <lmapibuf.h>
  11. #include <lmerr.h>
  12. #include <winsvc.h>
  13. #include <rasuip.h>
  14. #define MPR50 1
  15. #include <mprapi.h>
  16. #include <rtinfo.h>
  17. #include <ipxrtdef.h>
  18. #include <routprot.h>
  19. // Error reporting
  20. void PrintErr(DWORD err);
  21. // [pmay] This will be removed when the router is modified to use MprInfo api's
  22. typedef RTR_INFO_BLOCK_HEADER IPX_INFO_BLOCK_HEADER, *PIPX_INFO_BLOCK_HEADER;
  23. typedef RTR_TOC_ENTRY IPX_TOC_ENTRY, *PIPX_TOC_ENTRY;
  24. // Prototypes of functions that may be temporarily used for test.exe
  25. void FixFwd();
  26. DWORD DispPorts();
  27. DWORD EnumGroups ();
  28. DWORD Service();
  29. void Crash();
  30. // Return true if you want this function to implement test.exe
  31. BOOL TempFunc(int argc, char ** argv) {
  32. //Service();
  33. //return TRUE;
  34. return FALSE;
  35. }
  36. // Display ports
  37. DWORD DispPorts() {
  38. DWORD dwErr;
  39. HANDLE hRouterAdmin;
  40. if ((dwErr = MprAdminServerConnect(NULL, &hRouterAdmin)) != NO_ERROR)
  41. return dwErr;
  42. }
  43. PIPX_TOC_ENTRY
  44. GetIPXTocEntry (
  45. IN PIPX_INFO_BLOCK_HEADER pInterfaceInfo,
  46. IN ULONG InfoEntryType
  47. ) {
  48. UINT i;
  49. PIPX_TOC_ENTRY pTocEntry;
  50. for (i=0, pTocEntry = pInterfaceInfo->TocEntry;
  51. i<pInterfaceInfo->TocEntriesCount;
  52. i++, pTocEntry++) {
  53. if (pTocEntry->InfoType == InfoEntryType) {
  54. return pTocEntry;
  55. }
  56. }
  57. SetLastError (ERROR_FILE_NOT_FOUND);
  58. return NULL;
  59. }
  60. DWORD GetNbIpxClientIf (LPTSTR InterfaceName,
  61. UINT msg)
  62. {
  63. DWORD rc, sz;
  64. LPBYTE pClBlock;
  65. HANDLE hTrCfg, hRouterAdmin;
  66. if ((rc = MprAdminServerConnect(NULL, &hRouterAdmin)) != NO_ERROR)
  67. return rc;
  68. hTrCfg = NULL;
  69. rc = MprAdminTransportGetInfo (
  70. hRouterAdmin,
  71. PID_IPX,
  72. NULL, NULL,
  73. &pClBlock,
  74. &sz);
  75. if (rc==NO_ERROR) {
  76. PIPX_TOC_ENTRY pIpxToc, pSapToc, pRipToc;
  77. // Netbios
  78. pIpxToc = GetIPXTocEntry ((PIPX_INFO_BLOCK_HEADER)pClBlock,
  79. IPX_INTERFACE_INFO_TYPE);
  80. if (pIpxToc!=NULL) {
  81. PIPX_IF_INFO pIpxInfo;
  82. pIpxInfo = (PIPX_IF_INFO)(pClBlock+pIpxToc->Offset);
  83. printf("\nDial-in\n");
  84. printf("Accept = %d\n", pIpxInfo->NetbiosAccept);
  85. printf("Deliver = %d\n\n", pIpxInfo->NetbiosDeliver);
  86. pIpxInfo->NetbiosDeliver = 1;
  87. }
  88. // rip
  89. pRipToc = GetIPXTocEntry ((PIPX_INFO_BLOCK_HEADER)pClBlock,IPX_PROTOCOL_RIP);
  90. if (pIpxToc!=NULL) {
  91. PRIP_IF_CONFIG pRipCfg;
  92. pRipCfg = (PRIP_IF_CONFIG)(pClBlock+pRipToc->Offset);
  93. printf("\nDial-in\n");
  94. printf("Rip = %d\n", pRipCfg->RipIfInfo.UpdateMode);
  95. pRipCfg->RipIfInfo.UpdateMode = 2;
  96. }
  97. // sap
  98. pSapToc = GetIPXTocEntry ((PIPX_INFO_BLOCK_HEADER)pClBlock,IPX_PROTOCOL_SAP);
  99. if (pIpxToc!=NULL) {
  100. PSAP_IF_CONFIG pSapCfg;
  101. pSapCfg = (PSAP_IF_CONFIG)(pClBlock+pSapToc->Offset);
  102. printf("\nDial-in\n");
  103. printf("Sap Mode = %d\n\n\n", pSapCfg->SapIfInfo.UpdateMode);
  104. pSapCfg->SapIfInfo.UpdateMode = 2;
  105. }
  106. MprAdminTransportSetInfo(
  107. hRouterAdmin,
  108. PID_IPX,
  109. (LPBYTE)NULL,
  110. 0,
  111. pClBlock,
  112. sz);
  113. MprAdminBufferFree (pClBlock);
  114. }
  115. return rc;
  116. }
  117. void FixFwd() {
  118. GetNbIpxClientIf(NULL, 0);
  119. GetNbIpxClientIf(NULL, 0);
  120. }
  121. // Enumerates the local groups on the local machine
  122. DWORD EnumGroups () {
  123. NET_API_STATUS nStatus;
  124. GROUP_INFO_0 * buf;
  125. DWORD i, dwMax = 2000000, dwTot, dwRead=0;
  126. nStatus = NetLocalGroupEnum(NULL,
  127. 0,
  128. (LPBYTE*)&buf,
  129. dwMax,
  130. &dwRead,
  131. &dwTot,
  132. NULL);
  133. if (nStatus != NERR_Success) {
  134. switch (nStatus) {
  135. case ERROR_ACCESS_DENIED:
  136. return ERROR_ACCESS_DENIED;
  137. case NERR_UserExists:
  138. return ERROR_USER_EXISTS;
  139. case NERR_PasswordTooShort:
  140. return ERROR_INVALID_PASSWORDNAME;
  141. case NERR_InvalidComputer: // These should never happen because
  142. case NERR_NotPrimary: // we deal with local user database
  143. case NERR_GroupExists:
  144. default:
  145. return ERROR_CAN_NOT_COMPLETE;
  146. }
  147. }
  148. for (i=0; i<dwRead; i++)
  149. wprintf(L"Group Name: %s\n", buf[i].grpi0_name);
  150. return NO_ERROR;
  151. }
  152. // Runs tests on starting/stopping services, etc.
  153. DWORD Service() {
  154. SC_HANDLE hServiceController = NULL, hService = NULL;
  155. WCHAR pszRemoteAccess[] = L"remoteaccess";
  156. SERVICE_STATUS ServiceStatus;
  157. BOOL bOk;
  158. __try {
  159. // Open the service manager
  160. hServiceController = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, GENERIC_EXECUTE);
  161. if (! hServiceController) {
  162. PrintErr(GetLastError());
  163. return 0;
  164. }
  165. // Open the service
  166. hService = OpenServiceW(hServiceController,
  167. pszRemoteAccess,
  168. SERVICE_START | SERVICE_STOP | SERVICE_QUERY_STATUS);
  169. if (! hService) {
  170. PrintErr(GetLastError());
  171. return 0;
  172. }
  173. // Get the service status
  174. bOk = QueryServiceStatus (hService,
  175. &ServiceStatus);
  176. if (! bOk) {
  177. PrintErr(GetLastError());
  178. return 0;
  179. }
  180. // Find out if the service is running
  181. if (ServiceStatus.dwCurrentState == SERVICE_STOPPED) {
  182. printf("\nRemote access service is stopped, attempting to start it...");
  183. bOk = StartService(hService, 0, NULL);
  184. if (! bOk) {
  185. PrintErr(GetLastError());
  186. return 0;
  187. }
  188. // Wait for the service to stop
  189. while (ServiceStatus.dwCurrentState != SERVICE_RUNNING) {
  190. Sleep(1000);
  191. bOk = QueryServiceStatus (hService,
  192. &ServiceStatus);
  193. if (! bOk) {
  194. PrintErr(GetLastError());
  195. return 0;
  196. }
  197. printf(".");
  198. }
  199. printf("\nService Started.\n\n");
  200. }
  201. else if (ServiceStatus.dwCurrentState == SERVICE_RUNNING) {
  202. printf("\nRemote access service is started, attempting to stop it...");
  203. bOk = ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus);
  204. if (! bOk) {
  205. PrintErr(GetLastError());
  206. return 0;
  207. }
  208. // Wait for the service to stop
  209. while (ServiceStatus.dwCurrentState != SERVICE_STOPPED) {
  210. Sleep(1000);
  211. bOk = QueryServiceStatus (hService,
  212. &ServiceStatus);
  213. if (! bOk) {
  214. PrintErr(GetLastError());
  215. return 0;
  216. }
  217. printf(".");
  218. }
  219. printf("\nService Stopped.\n\n");
  220. }
  221. }
  222. __finally {
  223. if (hServiceController)
  224. CloseServiceHandle(hServiceController);
  225. if (hService)
  226. CloseServiceHandle(hService);
  227. }
  228. return 0;
  229. }
  230. /*
  231. char x [5] = { 0xf0, 0x0f, 0xc7, 0xc8 };
  232. void Crash() {
  233. {
  234. void (*f)() = x;
  235. f();
  236. }
  237. */